2
votes

I'm exporting a JAR that contains a class:

public class SerializerHelper {
    public String toJson(final Object src) {...}
}

And the trialApplicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="serializerHelper" class="com.trial.SerializerHelper"/>

</beans>

Then, I'm importing that JAR on another project, and on its applicationContext.xml I'm importing the trial context as follows:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<!-- Replace all @Autowired by its instances -->
    <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>

    <import resource="classpath*:trialApplicationContext"/>

    <bean id="booksSerializer" class="com.trial.BooksSerializerImpl" />
    ...

</beans>

And then, I'm using that bean on my class as:

public interface BooksSerializer {
    String getBooks();
}

public class BooksSerializerImpl implements BooksSerializer {

    @Autowired
    private SerializerHelper serializerHelper;

    ...

}

However, the code is failing with the following error:

java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'booksSerializer' defined in URL [...applicationContext.xml]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect bean class [com.trial.BooksSerializerImpl] for autowiring metadata: could not find class that it depends on java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'booksSerializer' defined in URL [jar:file:/....jar!/applicationContext.xml]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect bean class [com.trial.BooksSerializerImpl] for autowiring metadata: could not find class that it depends on at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:921) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:900) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:684) at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2044) at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1690) at com.sun.enterprise.web.WebApplication.start(WebApplication.java:107) at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122) java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'booksSerializer' defined in URL [jar:file:/....jar!/applicationContext]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect bean class [com.trial.BooksSerializerImpl] for autowiring metadata: could not find class that it depends on at com.sun.enterprise.web.WebApplication.start(WebApplication.java:136) at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122) java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productSerializer' defined in URL [jar:file:/....jar!/applicationContext.xml]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect bean class [com.trial.BooksSerializerImpl] for autowiring metadata: could not find class that it depends on at com.sun.enterprise.web.WebApplication.start(WebApplication.java:136) at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122) Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'booksSerializer' defined in URL [jar:file:/....jar!/applicationContext.xml]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect bean class [com.trial.BooksSerializerImpl] for autowiring metadata: could not find class that it depends on]]

This error is happening when I'm trying to run my project on a jersey server.

What am I doing wrong? Thanks a lot.

1
Where is your BooksSerializer interface? Did you put any annotation on that interface ?Ataur Rahman Munna
No, the interface has no annotations.FVod
Annotate your BooksSerializer interface with @Service and let me know the status.Ataur Rahman Munna
I've tried it, but, unfortunately, nothing changesFVod
Did you use <mvc:component-scan ="package">?Ataur Rahman Munna

1 Answers

1
votes

Please Use context component scan for scanning your package, so that your declare spring bean can be discoverable by spring container. Declare it in applicationContext.xml

<context:component-scan base-package="com.jartrial.*, com.trial.*" />