java.lang.NoSuchMethodError: org.neo4j.kernel.impl.transaction.SpringTransactionManager.<init>(Lorg/neo4j/graphdb/GraphDatabaseService;)V - spring

I am am starting to learn spring-data-neo4j
Very basic test case i am running but unable to succeed.
the error is: java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jRelationshipBacking' defined in class path resource [org/springframework/data/neo4j/aspects/config/Neo4jAspectConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.aspects.support.relationship.Neo4jRelationshipBacking org.springframework.data.neo4j.aspects.config.Neo4jAspectConfiguration.neo4jRelationshipBacking() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jTemplate' defined in class path resource [org/springframework/data/neo4j/aspects/config/Neo4jAspectConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.Neo4jTemplate org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jTemplate() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingInfrastructure' defined in class path resource [org/springframework/data/neo4j/aspects/config/Neo4jAspectConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.MappingInfrastructureFactoryBean org.springframework.data.neo4j.config.Neo4jConfiguration.mappingInfrastructure() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jTransactionManager' defined in class path resource [org/springframework/data/neo4j/aspects/config/Neo4jAspectConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.transaction.PlatformTransactionManager org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jTransactionManager()] threw exception; nested exception is java.lang.NoSuchMethodError: org.neo4j.kernel.impl.transaction.SpringTransactionManager.<init>(Lorg/neo4j/graphdb/GraphDatabaseService;)V
User.java pojo annotated with #NodeEntity
#NodeEntity
public class User {
#GraphId
private Long id;
User(String name){
this.name = name;
}
private String name;
public Long getId() {
return id;
}
public String getName() {
return name;
}
}
configuration file is:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config/>
<context:spring-configured/>
<neo4j:config storeDirectory="D:/data/db"/>
<tx:annotation-driven mode="proxy"/>
<context:component-scan base-package="com.neo4j.model"/>
</beans>
JUnit test case is :
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations={"classpath:/graph-test-context.xml"})
public class Neo4jUserTest {
#Autowired
Neo4jTemplate neo4jTemplate;
#Test
public void test() {
User user = new User("test");
neo4jTemplate.beginTx();
neo4jTemplate.save(user);
}
}
i have manually added below jar files from the eclipse buildpath:
commons-logging-1.0.4.jar
log4j-1.2.15.jar
jta.jar
cglib-2.1.3.jar
validation-api-1.0.0.GA.jar
lucene-core-3.5.0.jar
servlet-api.jar
org.springframework.aop-3.1.2.RELEASE.jar
org.springframework.asm-3.1.2.RELEASE.jar
org.springframework.aspects-3.1.2.RELEASE.jar
org.springframework.beans-3.1.2.RELEASE.jar
org.springframework.context.support-3.1.2.RELEASE.jar
org.springframework.context-3.1.2.RELEASE.jar
org.springframework.core-3.1.2.RELEASE.jar
org.springframework.expression-3.1.2.RELEASE.jar
org.springframework.instrument.tomcat-3.1.2.RELEASE.jar
org.springframework.instrument-3.1.2.RELEASE.jar
org.springframework.jdbc-3.1.2.RELEASE.jar
org.springframework.jms-3.1.2.RELEASE.jar
org.springframework.orm-3.1.2.RELEASE.jar
org.springframework.oxm-3.1.2.RELEASE.jar
org.springframework.test-3.1.2.RELEASE.jar
org.springframework.transaction-3.1.2.RELEASE.jar
org.springframework.web.portlet-3.1.2.RELEASE.jar
org.springframework.web.servlet-3.1.2.RELEASE.jar
org.springframework.web.struts-3.1.2.RELEASE.jar
org.springframework.web-3.1.2.RELEASE.jar
D:\JUnit\junit-4.6.jar
com.springsource.org.aopalliance-1.0.0.jar
aspectjtools-1.6.0.jar
asm-attrs.jar
asm.jar
spring-data-neo4j-2.1.0.RC1.jar
spring-data-neo4j-aspects-2.1.0.RC1.jar
spring-data-neo4j-cross-store-2.1.0.RC1.jar
spring-data-neo4j-rest-2.1.0.RC1.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.7.2.jar
geronimo-jta_1.1_spec-1.1.1.jar
lucene-core-3.5.0.jar
org.apache.servicemix.bundles.jline-0.9.94_1.jar
scala-library-2.9.0-1.jar
server-api-1.7.2.jar
spring-data-commons-core-1.3.1.RELEASE.jar
hamcrest-all-1.3.jar
neo4j-cypher-dsl-1.6.M02.jar
neo4j-cypher-1.9-20120912.103508-32.jar
neo4j-kernel-1.9-20120912.102607-33.jar
neo4j-lucene-index-1.9-20120912.103015-33.jar

As Peter said, the problem is you are including a different version of the Neo4J library than Spring is expecting. A NoSuchMethodError means a client is calling a method that doesn't exist. This couldn't happen if you include the version Spring is using becuase Spring would have got a compile error if they called a method that doesn't exist.
How are you building you project? Please provide more detail like a POM if its a maven project.
Update: The org.neo4j.kernel.impl.transaction.SpringTransactionManager comes from your Neo4J installation not the jars you are supplying. What version of Neo4J are you running? It needs to match the version that spring-data-neo4j is expecting.

It seems you are using an old Neo4j version. Could you try with the coresponding Neo4j version, I think 1.8 instead of 1.7.2?

Finally i solved it by using below jar files:
aopalliance-1.0.jar
asm-3.1.jar
aspectjrt-1.6.12.jar
backport-util-concurrent-3.1.jar
cglib-2.2.jar
codegen-0.5.5.jar
commons-cli-1.0.jar
ecj-3.7.2.jar
guava-11.0.2.jar
hamcrest-core-1.3.jar
hamcrest-library-1.3.jar
jakarta-regexp-1.4.jar
javax.inject-1.jar
jcl-over-slf4j-1.7.1.jar
jsr305-1.3.9.jar
jta.jar
junit-3.8.1.jar
junit-dep-4.10.jar
logback-classic-1.0.6.jar
logback-core-1.0.6.jar
lucene-core-3.5.0.jar
lucene-queries-3.5.0.jar
mysema-commons-lang-0.2.4.jar
neo4j-1.8.jar
neo4j-cypher-1.8.jar
neo4j-cypher-dsl-1.8.jar
neo4j-graph-algo-1.8.jar
neo4j-graph-matching-1.8.jar
neo4j-jmx-1.8.jar
neo4j-kernel-1.8.jar
neo4j-lucene-index-1.8.jar
neo4j-udc-1.8.jar
plexus-compiler-api-1.9.1.jar
plexus-compiler-javac-1.9.1.jar
plexus-compiler-manager-1.9.1.jar
plexus-interactivity-api-1.0-alpha-4.jar
plexus-interpolation-1.11.jar
plexus-interpolation-1.13.jar
plexus-utils-1.5.15.jar
plexus-utils-2.0.5.jar
plexus-utils-3.0.jar
querydsl-apt-2.8.2.jar
querydsl-codegen-2.8.2.jar
querydsl-core-2.8.2.jar
querydsl-lucene-2.8.2.jar
scala-library-2.9.1-1.jar
slf4j-api-1.7.1.jar
spring-aop-3.2.0.M2.jar
spring-aspects-3.2.0.M2.jar
spring-beans-3.2.0.M2.jar
spring-context-3.2.0.M2.jar
spring-core-3.2.0.M2.jar
spring-data-commons-core-1.4.0.RELEASE.jar
spring-data-neo4j-2.1.0.RELEASE.jar
spring-expression-3.2.0.M2.jar
spring-jdbc-3.2.0.M2.jar
spring-orm-3.2.0.M2.jar
spring-test-3.2.0.M2.jar
spring-tx-3.2.0.M2.jar
validation-api-1.0.0.GA.jar

Related

Issue with bean from another JAR

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.
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.*" />

Spring BeanPostProcessor BeanCreationException runtime error

I'm unable to launch hello world app with Spring 4.3.6 Please, help, I don't even know what may be wrong.
Without bean messageService and aop section everything works. But I got this error with config as it is
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'printer' defined in class path resource [config.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)#c273d3' of type [org.springframework.aop.aspectj.AspectJMethodBeforeAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#c273d3': Cannot create inner bean '(inner bean)#1423665' of type [org.springframework.aop.config.MethodLocatingFactoryBean] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1423665': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [MessagePrinterService] for bean with name 'messageService' defined in class path resource [config.xml]; nested exception is java.lang.ClassNotFoundException: MessagePrinterService
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [MessagePrinterService] for bean with name 'messageService' defined in class path resource [config.xml]; nested exception is java.lang.ClassNotFoundException: MessagePrinterService
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'printer' defined in class path resource [config.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)#c273d3' of type [org.springframework.aop.aspectj.AspectJMethodBeforeAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#c273d3': Cannot create inner bean '(inner bean)#1423665' of type [org.springframework.aop.config.MethodLocatingFactoryBean] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1423665': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [MessagePrinterService] for bean with name 'messageService' defined in class path resource [config.xml]; nested exception is java.lang.ClassNotFoundException: MessagePrinterService
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [MessagePrinterService] for bean with name 'messageService' defined in class path resource [config.xml]; nested exception is java.lang.ClassNotFoundException: MessagePrinterService
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:479)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
Xml config:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<bean id="printer" class="helloword.MessagePrinter">
<constructor-arg ref="message"></constructor-arg>
</bean>
<bean id="message" class="helloword.HelloWordMessage">
<constructor-arg value="Hello Spring World!"></constructor-arg>
</bean>
<bean id="messageService" class="MessagePrinterService">
</bean>
<aop:config>
<aop:aspect ref="messageService">
<aop:pointcut id="print" expression="execution(* *.print(..))"/>
<aop:before pointcut-ref="print" method="preMsg"/>
<aop:after pointcut-ref="print" method="postMsg"/>
</aop:aspect>
</aop:config>
</beans>
Classes, all is separate files:
public class HelloWordMessage implements Message{
private String msg;
public HelloWordMessage(String s) {
msg = s;
}
#Override
public String getText() {
return msg;
}
}
public class MessagePrinter implements Printer {
private Message msg;
public MessagePrinter(Message m){
msg = m;
}
#Override
public void print(){
System.out.println(msg.getText());
}
}
public class MessagePrinterService {
public MessagePrinterService(){
System.out.println("MessagePrinterService created");
}
public void preMsg(){
System.out.println("Message alert!:");
}
public void postMsg(){
System.out.println("End of message.");
}
}
public class Aplication {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("config.xml");
MessagePrinter printer = context.getBean(MessagePrinter.class);
printer.print();
context.close();
}
}
java.lang.ClassNotFoundException: MessagePrinterService
Spring cannot load the class MessagePrinterService.
Put it into a specific package and change the configuration accordingly. It should work then.

Instantiation of bean failed : Specified class is an interface

I am facing an issue while creating a bean for dependency injection. Here is the scenario.
I am dealing with MongoDB repository, I have also created a class which uses it. I am trying to instantiate bean instance of both.
MongoDB reporsitory:
#Repository
public interface ProductGlobalTrendRepository extends MongoRepository<ProductGlobalTrend,String>{
public ProductGlobalTrend findByPid(#Param("pId") String pId);
}
The class which is using it:
#Service
#Scope("singleton")
public class ProductTrendService {
#Autowired
#Qualifier("productGlobalTrendRepo")
ProductGlobalTrendRepository productGlobalTrendRepo;
public ProductTrendService() {
super();
}
public void setProductGlobalTrendRepo(
ProductGlobalTrendRepository productGlobalTrendRepo) {
this.productGlobalTrendRepo = productGlobalTrendRepo;
}
public ProductTrendService(ProductGlobalTrendRepository productGlobalTrendRepo) {
super();
this.productGlobalTrendRepo = productGlobalTrendRepo;
}
}
The spring's bean config xml has these entries:
<bean id="productTrendService" class="com.api.services.ProductTrendService"> </bean>
<bean id="productGlobalTrendRepo" class="com.mongodb.repository.ProductGlobalTrendRepository"> </bean>
Following is the error I am getting:
19428 [localhost-startStop-1] WARN
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
- Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'productTrendService': Injection of autowired
dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire field: com.mongodb.repository.ProductGlobalTrendRepository
com.api.services.ProductTrendService.productGlobalTrendRepo; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'productGlobalTrendRepo' defined in
class path resource [com/vstore/conf/spring-security.xml]:
Instantiation of bean failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [com.mongodb.repository.ProductGlobalTrendRepository]:
Specified class is an interface
It complains that repository is a interface class.
Can somebody please suggest a fix/workaround for this bean dependency injection ?
The problem is with the following information in your context file
<bean id="productGlobalTrendRepo"
class="com.mongodb.repository.ProductGlobalTrendRepository">
</bean>
You should create a class com.mongodb.repository.ProductGlobalTrendRepositoryImpl which implements com.mongodb.repository.ProductGlobalTrendRepository and provides implementation of its methods.
then change your bean declaration info as
<bean id="productGlobalTrendRepo"
class="com.mongodb.repository.ProductGlobalTrendRepositoryImpl">
</bean>
Behind the scene the object is created which is not possible with the interface.

EJB3 interceptor cannot bootstrap context

I'm trying to inject Spring beans into an EJB using
#Interceptors(SpringBeanAutowiringInterceptor.class)
Here's my EJB:
#Stateless
#Interceptors(SpringBeanAutowiringInterceptor.class)
public class processMethodService implements
processMethodService {
#Autowired
private SomeBean bean;
#Schedule(minute = "*/5", hour = "*", persistent = false)
#TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void startProcessing() {
//businesslogic
}
}
And beanRefContext.xml as follows
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<bean id="ejb-businesslayer.application.context" lazy-init="true"
class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg>
<list>
<value>classpath:/META-INF/spring-config.xml</value>
</list>
</constructor-arg>
</bean> `
beanRefContext.xml,spring-config.xml are under META-INF folder.
when startProcessing is called for every 5 minutes and we are getting the below exception
Exception data: javax.ejb.EJBException: session bean lifecycle interceptor failure;nested exception is:org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [null],
from group with resource name [classpath*:beanRefContext.xml];
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [org.springframework.beans.factory.BeanFactory] is defined
Please find the complete exception as below
Exception data: javax.ejb.EJBException: session bean lifecycle interceptor failure;nested exception is: org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [null], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.beans.factory.BeanFactory] is defined`enter code here`
at com.ibm.ejs.container.util.ExceptionUtil.EJBException(ExceptionUtil.java:466)
at com.ibm.ejs.container.SessionBeanO.callLifecycleInterceptors(SessionBeanO.java:288)
at com.ibm.ejs.container.StatelessBeanO.initialize(StatelessBeanO.java:399)
at com.ibm.ejs.container.BeanOFactory.create(BeanOFactory.java:147)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1238)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1356)
at com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate(UncachedActivationStrategy.java:88)
at com.ibm.ejs.container.activator.Activator.preInvokeActivateBean(Activator.java:615)
at com.ibm.ejs.container.EJSContainer.preInvokeActivate(EJSContainer.java:4205)
at com.ibm.ejs.container.EJSContainer.EjbPreInvoke(EJSContainer.java:3535)
at com.ibm.ejs.container.TimedObjectWrapper.invokeCallback(TimedObjectWrapper.java:110)
at com.ibm.ejs.container.TimerNpListener.doWork(TimerNpListener.java:293)
at com.ibm.ejs.container.TimerNpListener.doWorkWithRetries(TimerNpListener.java:171)
at com.ibm.ejs.container.TimerNpListener.fired(TimerNpListener.java:141)
at com.ibm.ws.asynchbeans.AlarmImpl.callListenerMethod(AlarmImpl.java:427)
at com.ibm.ws.asynchbeans.timer.GenericTimer.run(GenericTimer.java:228)
at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:1178)
at com.ibm.ws.asynchbeans.AlarmImpl.runListenerAsCJWork(AlarmImpl.java:249)
at com.ibm.ws.asynchbeans.am._Alarm.fireAlarm(_Alarm.java:333)
at com.ibm.ws.asynchbeans.am._Alarm.run(_Alarm.java:230)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1783)
Caused by: org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [null], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.beans.factory.BeanFactory] is defined
at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:402)
at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactoryReference(SpringBeanAutowiringInterceptor.java:160)
at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactory(SpringBeanAutowiringInterceptor.java:141)
at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.doAutowireBean(SpringBeanAutowiringInterceptor.java:121)
at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.autowireBean(SpringBeanAutowiringInterceptor.java:95)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:613)
at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor(InterceptorProxy.java:227)
at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:548)
at com.ibm.ejs.container.interceptors.InvocationContextImpl.doLifeCycle(InvocationContextImpl.java:273)
at com.ibm.ejs.container.SessionBeanO.callLifecycleInterceptors(SessionBeanO.java:274)
Please guide me on how to resolve this error
The ContextSingletonBeanFactoryLocator is looking for resource classpath*:beanRefContext.xml, so the beanRefContext.xml file has to be in the classpath, ref this link,
Move beanRefContext.xml into a folder that's in the class path and that should solve the problem.
First off, I think removing META-INF should help. Also, I just solved this same issue by moving context in question to /resources directory

autowiring jee-jdni-lookup datasource entry in spring-config to #repository dao impl class

I am using #repository annotation for DAO impl classes but not able to #autowire or #resource the datasource defined in beanRefContext.xml configuration as
jee:jndi-lookup tag
I have all the required tag entries in place, like annotation and component package scan
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/xyzName"
cache="true" resource-ref="true" lookup-on-startup="false"
proxy-interface="javax.sql.DataSource" />
I tried following in #Repository impl class,
#Resource(mappedName="jdbc/xyzName")
private DataSource dataSource;
#Resource(name="datasource")
private DataSource dataSource;
#Autowired
private DataSource dataSource;
Please help!
######### Main xml file ##########
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- This will automatically declare several post-processors
including the AutowiredAnnotationBeanPostProcessor -->
<context:annotation-config/>
<context:component-scan base-package="com.domain"/>
<bean id="context" lazy-init="true"
class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg value="ejbBeans.xml" />
</bean>
</beans>
########## EJB beans xml file ################
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<tx:annotation-driven transaction-manager="someTransactionManager" />
<bean
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor">
<property name="alwaysUseJndiLookup" value="true" />
</bean>
<bean id="someTransactionManager"
class="org.springframework.transaction.jta.WebSphereUowTransactionManager">
</bean>
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/xyzName"
cache="true" resource-ref="true" lookup-on-startup="false"
proxy-interface="javax.sql.DataSource" />
</beans>
Now getting below exception java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required..the below is the code for my DAOImpl class
#Repository
public class UtilityDAOImpl extends JdbcDaoSupport implements
UtilityDAO {
final String className = UtilityDAOImpl.class.getName();
private JdbcTemplate jdbcTemplate ;
#Autowired
#Qualifier("dataSource")
public void setJdbcTemplate(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
EDIT: Got this exception
; nested exception is: org.springframework.beans.factory.access.BootstrapException: Unable to initialize group definition. Group resource name [classpath*:beanRefContext.xml], factory key [null]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ProgramEligiblityEventCheckController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao.vista.VistaEligiblityEventDAO com...domain.core.claim.ProgramEligiblityEventCheckController.vistaEligiblityEventDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vistaEligiblityEventDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao..UtilityDAO com...domain.dao.vista.impl.VistaEligiblityEventDAOImpl.utilityDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UtilityDAOImpl' defined in file [C:\workspace_1.2\ejb12\ejbModule\com\\\domain\dao\\impl\UtilityDAOImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
org.springframework.beans.factory.access.BootstrapException: Unable to initialize group definition. Group resource name [classpath*:beanRefContext.xml], factory key [null]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ProgramEligiblityEventCheckController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao.vista.VistaEligiblityEventDAO com...domain.core.claim.ProgramEligiblityEventCheckController.vistaEligiblityEventDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vistaEligiblityEventDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao..UtilityDAO com...domain.dao.vista.impl.VistaEligiblityEventDAOImpl.utilityDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UtilityDAOImpl' defined in file [C:\workspace_1.2\ejb12\ejbModule\com\\\domain\dao\\impl\UtilityDAOImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:386)
at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactoryReference(SpringBeanAutowiringInterceptor.java:160)
at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactory(SpringBeanAutowiringInterceptor.java:141)
at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.doAutowireBean(SpringBeanAutowiringInterceptor.java:121)
at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.autowireBean(SpringBeanAutowiringInterceptor.java:95)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:600)
at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor(InterceptorProxy.java:227)
at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:566)
at com.ibm.ejs.container.interceptors.InvocationContextImpl.doLifeCycle(InvocationContextImpl.java:264)
at com.ibm.ejs.container.SessionBeanO.callPostConstructInterceptors(SessionBeanO.java:260)
at com.ibm.ejs.container.StatelessBeanO.initialize(StatelessBeanO.java:409)
at com.ibm.ejs.container.CMStatelessBeanOFactory.create(CMStatelessBeanOFactory.java:45)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1031)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1141)
at com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate(UncachedActivationStrategy.java:84)
at com.ibm.ejs.container.activator.Activator.activateBean(Activator.java:599)
at com.ibm.ejs.container.EJSContainer.preInvokeActivate(EJSContainer.java:3964)
at com.ibm.ejs.container.EJSContainer.EjbPreInvoke(EJSContainer.java:3349)
at com..domain.ejb.facade.EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c.processRequest(EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c.java)
at com..domain.ejb.facade._EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c_Tie.processRequest(_EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c_Tie.java)
at com..domain.ejb.facade._EJSRemote0SLRequestDelegatorFacad_35bfd46c_Tie._invoke(_EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c_Tie.java)
at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:622)
at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:475)
at com.ibm.rmi.iiop.ORB.process(ORB.java:513)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:1574)
at com.ibm.rmi.iiop.Connection.respondTo(Connection.java:2841)
at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2714)
at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:63)
at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ProgramEligiblityEventCheckController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao.vista.VistaEligiblityEventDAO com.domain.core.claim.ProgramEligiblityEventCheckController.vistaEligiblityEventDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vistaEligiblityEventDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao..UtilityDAO com...domain.dao.vista.impl.VistaEligiblityEventDAOImpl.utilityDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UtilityDAOImpl' defined in file [C:\workspace_1.2\ejb12\ejbModule\com\\\domain\dao\\impl\UtilityDAOImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.context.access.ContextSingletonBeanFactoryLocator.initializeDefinition(ContextSingletonBeanFactoryLocator.java:143)
at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:381)
... 32 more
And the class in question
#Repository
public class TempUtilityDAOImpl extends JdbcDaoSupport implements
TempUtilityDAO {
final String className = TempUtilityDAOImpl.class.getName();
private JdbcTemplate jdbcTemplate ;
#Autowired
#Qualifier("dataSource")
public void setJdbcTemplate(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
private static String IS_DEALER_IN_Temp = "select count(id_dlr) from "
+ TempConstants.DB_NAME_Temp + "V_Temp_DLR where id_dlr = ? with UR";
/**
* Method verifies that Dealer is not an Canadian dealer.
*
* #param dealerID
* #return
* #throws TempSystemException
*/
public boolean verifyTempDealer(String dealerID) throws TempSystemException {
boolean isTempDealer = false;
final String methodName = "verifyTempDealer(String dealerID)";
MSLog.debug(className, "Exiting Method : " + methodName);
int rowcount = getJdbcTemplate().queryForInt(IS_DEALER_IN_Temp,
dealerID);
if (rowcount > 0) {
isTempDealer = true;
}
MSLog.debug(className, "Exiting Method : " + methodName);
return isTempDealer;
}
}
I don't know that
<bean id="context" lazy-init="true"
class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg value="ejbBeans.xml" />
</bean>
can import beans from one context to another.
You should use
<import resource="ejbBeans.xml"/>
All beans declared in ejbBeans.xml will then be available in your importing context.

Resources