Announcement Announcement Module
Collapse
No announcement yet.
Not using JNDI but get JNDI lookup failed error! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Not using JNDI but get JNDI lookup failed error!

    I am using Spring 3 with EclipseLink... I am in test phase with Junit testing and do not have any AS yet.

    The problem is I will connect to DB and everything was allright when I did it with Hibernate/SessionFactory, but since I am trying to use EclipseLink/EntityManagerFactory ... get strange JNDI Lookup failed error. And I am sure that I do not use any JNDI right now.

    my persistence unit in my persistence.xml file:
    HTML Code:
    <persistence-unit name="milins-domain"
    		transaction-type="RESOURCE_LOCAL">
    		<provider>
                org.eclipse.persistence.jpa.PersistenceProvider
            </provider>		<class>se.lantmateriet.milins.domain.inskrivning.IrFastighet</class>
    		<class>se.lantmateriet.milins.domain.inskrivning.GroupInfo</class>
    		<class>se.lantmateriet.milins.domain.inskrivning.FastighetUUID</class>
    	</persistence-unit>
    and my dataSource info
    HTML Code:
    	 <bean id="milinsDataSource" 
    	 class="org.springframework.jdbc.datasource.SingleConnectionDataSource" 
    	 p:driverClassName="${jdbc.driverclassname}" 
    	 p:url="${milins.jdbc.url}" 
    	 p:suppressClose="true" 
    	 p:username="${milins.jdbc.username}" 
    	 p:password="${milins.jdbc.password}"/> 
    and my EntityManagerFactory settings
    HTML Code:
    	<!-- Milins Hibernate EntityManagerFactory -->
    	<bean id="milinsEntityManagerFactory"
    		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    		p:persistenceXmlLocation="classpath*:META-INF/persistence.xml"
    		p:dataSource-ref="milinsDataSource" p:jpaVendorAdapter-ref="jpaVendorAdapter"
    		p:persistenceUnitName="milins-domain">
    
    		<property name="jpaDialect">
    			<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
    		</property>
    		<property name="jpaProperties">
    			<props>
    				<prop key="eclipselink.weaving">false</prop><!-- <prop key="eclipselink.ddl-generation">drop-and-create-tables</prop> 
    					<prop key="eclipselink.ddl-generation.output-mode">sql-script</prop> -->
    				<prop key="eclipselink.application-location">src/test/resources/</prop>
    				<!-- Make us participate in JBoss JTA transactions -->
    				<!-- <prop key="eclipselink.target-server">org.eclipse.persistence.platform.server.jboss.JBossPlatform</prop> -->
    			</props>
    		</property>
    	</bean>
    
    	<bean id="milinsEntityManager"
    		class="org.springframework.orm.jpa.support.SharedEntityManagerBean"
    		p:entityManagerFactory-ref="milinsEntityManagerFactory" />
    
    	<bean id="milinsTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
    		p:entityManagerFactory-ref="milinsEntityManagerFactory" />
    when I am trying to start testing .... the following error message appears
    Code:
    Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    and with more details:
    Code:
    ......
    Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'milinsEntityManager' defined in JNDI environment: JNDI lookup failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    	at org.springframework.jndi.support.SimpleJndiBeanFactory.getBean(SimpleJndiBeanFactory.java:117)
    	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:400)
    	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541)
    	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
    	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
    	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297)
    	... 56 more
    Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
    	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
    	at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
    	at javax.naming.InitialContext.lookup(InitialContext.java:392)
    	at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
    	at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
    	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
    	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
    	at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104)
    	at org.springframework.jndi.support.SimpleJndiBeanFactory.getBean(SimpleJndiBeanFactory.java:107)
    	... 61 more
    It is almost 48 hours that I have been stopped with this stupid error!
    Hope some one can help me.

  • #2
    Can you post a single test class (that fails) with required configurations

    Comment


    • #3
      Why do you use the sharedentitymanagerbean, you have the LocalEntityManagerFactoryBean and don't need the shared one... Remove it, that is the source of your problem (that is also what your stacktrace is indicating).

      Comment


      • #4
        Maybe a bit quick to respond, can you post the FULL stacktrace... In general that is quite informative and I have the feeling that there is something missing from the stacktrace you posted.

        Comment


        • #5
          Originally posted by Marten Deinum View Post
          Maybe a bit quick to respond, can you post the FULL stacktrace... In general that is quite informative and I have the feeling that there is something missing from the stacktrace you posted.
          If I remove SharedEntityManager class ... the stacktrace is (i will attach the rest later ... cannot insert more than 10000 characters!)

          Code:
          2011-01-12 14:37:05,307 [main] ERROR Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@ea5461] to prepare test instance [se.lantmateriet.milins.dao.eclipselink.TestIrFastighetDaoEclipseLink@82d210] at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:324)
          java.lang.IllegalStateException: Failed to load ApplicationContext
          	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308)
          	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
          	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
          	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
          	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)
          	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
          	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
          	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
          	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
          	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
          	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
          	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
          	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
          	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
          	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
          	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
          	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
          	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
          	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
          	at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59)
          	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:115)
          	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:102)
          	at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
          	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          	at java.lang.reflect.Method.invoke(Method.java:597)
          	at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
          	at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
          Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'irFastighetServices' defined in file [D:\workspace\milins\milins-data-access-layer\target\classes\se\lantmateriet\milins\servicesImpl\IrFastighetServicesImpl.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [se.lantmateriet.milins.dao.IrFastighetDao]: : Error creating bean with name 'irFastighetDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'milinsEntityManager' defined in JNDI environment: JNDI lookup failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'irFastighetDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'milinsEntityManager' defined in JNDI environment: JNDI lookup failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
          	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:730)
          	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1003)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:907)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
          	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
          	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
          	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
          	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
          	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
          	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)
          	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
          	at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280)
          	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304)
          	... 28 more
          Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'irFastighetDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'milinsEntityManager' defined in JNDI environment: JNDI lookup failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
          	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
          	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
          	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
          	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:844)
          	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:786)
          	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
          	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795)
          	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723)
          	... 44 more
          ......

          Comment


          • #6
            Originally posted by Marten Deinum View Post
            Maybe a bit quick to respond, can you post the FULL stacktrace... In general that is quite informative and I have the feeling that there is something missing from the stacktrace you posted.
            and the rest without SharedEntityManager

            Code:
            Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'milinsEntityManager' defined in JNDI environment: JNDI lookup failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
            	at org.springframework.jndi.support.SimpleJndiBeanFactory.getBean(SimpleJndiBeanFactory.java:117)
            	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:400)
            	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541)
            	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
            	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
            	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297)
            	... 56 more
            Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
            	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
            	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
            	at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
            	at javax.naming.InitialContext.lookup(InitialContext.java:392)
            	at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
            	at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
            	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
            	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
            	at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104)
            	at org.springframework.jndi.support.SimpleJndiBeanFactory.getBean(SimpleJndiBeanFactory.java:107)
            	... 61 more

            Comment


            • #7
              Originally posted by Marten Deinum View Post
              Maybe a bit quick to ...
              And with SharedEntityManager class:

              Code:
              java.lang.IllegalStateException: Failed to load ApplicationContext
              	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308)
              	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
              	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
              	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
              	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)
              	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
              	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
              	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
              	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
              	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
              	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
              	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
              	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
              	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
              	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
              	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
              	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
              	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
              	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
              	at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59)
              	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:115)
              	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:102)
              	at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
              	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              	at java.lang.reflect.Method.invoke(Method.java:597)
              	at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
              	at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
              Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'irFastighetServices' defined in file [D:\workspace\milins\milins-data-access-layer\target\classes\se\lantmateriet\milins\servicesImpl\IrFastighetServicesImpl.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [se.lantmateriet.milins.dao.IrFastighetDao]: : Error creating bean with name 'irFastighetDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'milinsEntityManager' defined in JNDI environment: JNDI lookup failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'irFastighetDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'milinsEntityManager' defined in JNDI environment: JNDI lookup failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
              	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:730)
              	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196)
              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1003)
              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:907)
              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
              	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
              	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
              	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
              	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
              	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
              	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
              	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
              	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)
              	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
              	at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280)
              	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304)
              	... 28 more
              Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'irFastighetDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'milinsEntityManager' defined in JNDI environment: JNDI lookup failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
              	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300)
              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
              	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
              	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
              	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
              	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
              	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:844)
              	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:786)
              	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
              	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795)
              	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723)
              	... 44 more
              Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'milinsEntityManager' defined in JNDI environment: JNDI lookup failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
              	at org.springframework.jndi.support.SimpleJndiBeanFactory.getBean(SimpleJndiBeanFactory.java:117)
              	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:400)
              	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541)
              	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
              	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
              	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297)
              	... 56 more
              
              ....
              the rest of stack trace comes in next post.

              Comment


              • #8
                Originally posted by Marten Deinum View Post
                Maybe a bit quick to respond, can you post the FULL stacktrace... In general that is quite informative and I have the feeling that there is something missing from the stacktrace you posted.
                Code:
                ...
                Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
                	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
                	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
                	at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
                	at javax.naming.InitialContext.lookup(InitialContext.java:392)
                	at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
                	at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
                	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
                	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
                	at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104)
                	at org.springframework.jndi.support.SimpleJndiBeanFactory.getBean(SimpleJndiBeanFactory.java:107)
                	... 61 more

                Comment


                • #9
                  Originally posted by amiladomingo View Post
                  Can you post a single test class (that fails) with required configurations
                  I have send all configuration that needed. The test class for example

                  Code:
                  @TransactionConfiguration(transactionManager = "levfrTransactionManager", defaultRollback = false)
                  @Transactional
                  public class TestLevfrFastighetUuidDaoEclipseLink extends AbstractBaseTest {
                  
                  	@Autowired
                  	LevfrFastighetUuidDao levfrFastighetUuidDao;
                  
                  	@Test
                  	public void testGetAll() {
                  
                  		assertNotNull(levfrFastighetUuidDao);
                  		List<LevfrFastighetUuid> fastighetUuids = levfrFastighetUuidDao
                  				.getAllFastighetUUIDs();
                  
                  		assertNotNull(fastighetUuids);
                  
                  	}
                  
                  }
                  And I am using annotation in my Daos to tel spring. As I told u before, all my codes worked with Hibernate and Session Factory .... so I guess something is wrong with my new settings with EclipseLink and EntityManagerFactory.

                  Thanks for helping

                  Comment


                  • #10
                    Can you post your full configuration and your dao...

                    Comment


                    • #11
                      Originally posted by Marten Deinum View Post
                      Can you post your full configuration and your dao...
                      Persistence.xml
                      HTML Code:
                      <?xml version="1.0" encoding="UTF-8"?>
                      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                      	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                      			   					 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                      	version="1.0">
                      
                      	<persistence-unit name="milins-domain"
                      		transaction-type="RESOURCE_LOCAL">
                      		<provider>
                                  org.eclipse.persistence.jpa.PersistenceProvider
                              </provider>
                      <!--        <jta-data-source>jdbc/milinsDataSource</jta-data-source>-->
                      		<class>myPackage.myClass1</class>
                      		<class>myPackage.myClass2</class>
                      		<class>myPackage.myClass3</class>
                      	</persistence-unit>
                      	
                      	<persistence-unit name="levfr-domain"
                      		transaction-type="RESOURCE_LOCAL">
                      		<provider>
                                  org.eclipse.persistence.jpa.PersistenceProvider
                              </provider>
                      		<class>myPackage.myClass4</class>
                      	</persistence-unit>	
                      
                      </persistence>
                      Spring-master.xml
                      HTML Code:
                      <?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"
                      	xmlns:context="http://www.springframework.org/schema/context"
                      	xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
                      	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
                      	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                      		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                      		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
                      
                      	<bean
                      		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                      		<property name="locations">
                      			<list>
                      				<!-- <value>classpath:projectsettings.properties</value> -->
                      				<value>file:${user.home}/milins.properties</value>
                      				<value>file:${user.home}/milins.test.properties</value>
                      			</list>
                      		</property>
                      		<property name="ignoreResourceNotFound" value="false" />
                      	</bean>
                      	<context:component-scan base-package="se.lantmateriet.milins">
                      <!--		<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>-->
                      		<context:exclude-filter expression="org.springframework.stereotype.Repository" type="annotation"/>
                      	</context:component-scan>
                      	
                          <!-- This will ensure that hibernate or jpa exceptions are automatically translated into
                               Spring's generic DataAccessException hierarchy -->
                          <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
                      	
                      	<import resource="spring-datasource.xml"/>
                      	
                      	<!--We should import spring-jpa.xml if we would like to use JPA (EntityManager)-->
                      	<import resource="spring-eclipselink.xml" />
                      </beans>
                      Spring-datasource.xml
                      HTML Code:
                      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
                      <beans xmlns="http://www.springframework.org/schema/beans"
                      	xmlns:p="http://www.springframework.org/schema/p" xmlns:jee="http://www.springframework.org/schema/jee"
                      	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-3.0.xsd
                                                 http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
                      
                      	 <bean id="milinsDataSource" 
                      	 class="org.springframework.jdbc.datasource.SingleConnectionDataSource" 
                      	 p:driverClassName="${jdbc.driverclassname}" 
                      	 p:url="${milins.jdbc.url}" 
                      	 p:suppressClose="true" 
                      	 p:username="${milins.jdbc.username}" 
                      	 p:password="${milins.jdbc.password}"/> 
                      
                      <!--This setting should be used when we will start using JBoss (an AS)-->
                      <!--	<bean id="milinsDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"-->
                      <!--		p:jndiName="jdbc/milinsDataSource" p:resourceRef="true" />-->
                      
                      
                      	 <bean id="levfrDataSource" 
                      	 autowire-candidate="false" 
                      	 class="org.springframework.jdbc.datasource.SingleConnectionDataSource" 
                      	 p:driverClassName="${jdbc.driverclassname}" 
                      	 p:url="${levfr.jdbc.url}" 
                      	 p:suppressClose="true" 
                      	 p:username="${levfr.jdbc.username}" 
                      	 p:password="${levfr.jdbc.password}"/> 
                      
                      <!--	<bean id="levfrDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"-->
                      <!--		p:jndiName="jdbc/levfrDataSource" p:resourceRef="true" />-->
                      
                      </beans>
                      Spring.eclipselink.xml
                      HTML Code:
                      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
                      <beans xmlns="http://www.springframework.org/schema/beans"
                      	xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
                      	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
                      	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-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/tx
                                                 http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                      
                      	<bean id="jpaVendorAdapter"
                      		class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"
                      		p:databasePlatform="org.eclipse.persistence.platform.database.OraclePlatform"
                      		p:generateDdl="false" p:showSql="true" />
                      
                      	<!-- Milins Hibernate EntityManagerFactory -->
                      	<bean id="milinsEntityManagerFactory"
                      		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
                      		p:persistenceXmlLocation="classpath*:META-INF/persistence.xml"
                      		p:dataSource-ref="milinsDataSource" p:jpaVendorAdapter-ref="jpaVendorAdapter"
                      		p:persistenceUnitName="milins-domain">
                      
                      		<property name="jpaDialect">
                      			<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
                      		</property>
                      		<property name="jpaProperties">
                      			<props>
                      				<prop key="eclipselink.weaving">false</prop><!-- <prop key="eclipselink.ddl-generation">drop-and-create-tables</prop> 
                      					<prop key="eclipselink.ddl-generation.output-mode">sql-script</prop> -->
                      				<prop key="eclipselink.application-location">src/test/resources/</prop>
                      				<!-- Make us participate in JBoss JTA transactions -->
                      				<!-- <prop key="eclipselink.target-server">org.eclipse.persistence.platform.server.jboss.JBossPlatform</prop> -->
                      			</props>
                      		</property>
                      	</bean>
                      
                      	<bean id="milinsEntityManager"
                      		class="org.springframework.orm.jpa.support.SharedEntityManagerBean"
                      		p:entityManagerFactory-ref="milinsEntityManagerFactory" />
                      
                      	<bean id="milinsTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
                      		p:entityManagerFactory-ref="milinsEntityManagerFactory" />
                      
                      	<!-- LevFR Hibernate SessionFactory -->
                      	<bean id="levfrEntityManagerFactory"
                      		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
                      		p:persistenceXmlLocation="classpath*:META-INF/persistence.xml"
                      		p:dataSource-ref="levfrDataSource" p:jpaVendorAdapter-ref="jpaVendorAdapter"
                      		p:persistenceUnitName="levfr-domain">
                      
                      		<property name="jpaDialect">
                      			<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
                      		</property>
                      		<property name="jpaProperties">
                      			<props>
                      				<prop key="eclipselink.weaving">false</prop><!-- <prop key="eclipselink.ddl-generation">drop-and-create-tables</prop> 
                      					<prop key="eclipselink.ddl-generation.output-mode">sql-script</prop> -->
                      				<prop key="eclipselink.application-location">src/test/resources/</prop>
                      				<!-- Make us participate in JBoss JTA transactions -->
                      				<!-- <prop key="eclipselink.target-server">org.eclipse.persistence.platform.server.jboss.JBossPlatform</prop> -->
                      			</props>
                      		</property>
                      	</bean>
                      
                      	<bean id="levfrEntityManager"
                      		class="org.springframework.orm.jpa.support.SharedEntityManagerBean"
                      		p:entityManagerFactory-ref="levFREntityManagerFactory" />
                      
                      	<bean id="levfrTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
                      		p:entityManagerFactory-ref="levFREntityManagerFactory" />
                      
                      	<!-- Read in DAOs from the eclipselink package -->
                      	<context:component-scan base-package="se.lantmateriet.milins.dao.eclipselink" />
                      
                      	<!-- Enable @Repository, @PersistenceContext support -->
                      	<bean
                      		class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
                      
                      	<!-- Enable @Transactional support -->
                      	<tx:annotation-driven />
                      
                      </beans>

                      one of my dao in next post....
                      Last edited by Sheri; Jan 13th, 2011, 01:07 AM.

                      Comment


                      • #12
                        Originally posted by Marten Deinum View Post
                        Can you post your full configuration and your dao...
                        And my DAOs

                        My GenericDao
                        Code:
                        package se.lantmateriet.milins.dao.eclipselink;
                        
                        import java.lang.reflect.ParameterizedType;
                        
                        import javax.annotation.Resource;
                        import javax.persistence.EntityManager;
                        
                        import org.springframework.beans.factory.annotation.Autowired;
                        import org.springframework.transaction.annotation.Transactional;
                        
                        import se.lantmateriet.milins.dao.GenericDao;
                        import se.lantmateriet.milins.domain.AbstractDomainMigrationInfo;
                        
                        public class GenericDaoEclipseLink<T extends AbstractDomainMigrationInfo>
                        		implements GenericDao<T> {
                        
                        	private Class<T> type;
                        
                        	@Autowired
                        	@Resource(mappedName = "milinsEntityManager")
                        	protected EntityManager entityManager;
                        
                        	@Override
                        	public void setEntityManager(final EntityManager entityManager) {
                        		this.entityManager = entityManager;
                        	}
                        
                        	@SuppressWarnings("unchecked")
                        	public GenericDaoEclipseLink() {
                        		this.type = (Class<T>) ((ParameterizedType) this.getClass()
                        				.getGenericSuperclass()).getActualTypeArguments()[0];
                        	}
                        
                        	//
                        	//
                        	// public GenericDaoEclipseLink(Class<T> type) {
                        	// super();
                        	// this.type = type;
                        	// }
                        
                        	@Override
                        	@Transactional
                        	public T create(final T o) {
                        		this.entityManager.persist(o);
                        		return o;
                        	}
                        
                        	@Override
                        	@Transactional
                        	public void save(final T o) {
                        		T object = this.fetch(o.getId());
                        		if (object == null) {
                        			// Object does not exists, so safe to merge..
                        			// if the object does not exist, merge will create new entity in db
                        			this.entityManager.merge(o);
                        		}
                        	}
                        
                        	@Override
                        	@Transactional
                        	public void delete(final T o) {
                        		this.entityManager.remove(this.fetch(o.getId()));
                        	}
                        
                        	@Override
                        	@Transactional
                        	public T fetch(final Long id) {
                        		return this.entityManager.find(this.type, id);
                        	}
                        }
                        One of my Dao
                        Code:
                        package se.lantmateriet.milins.dao.eclipselink;
                        
                        import java.util.List;
                        
                        import org.springframework.dao.DataAccessException;
                        import org.springframework.stereotype.Repository;
                        
                        import se.lantmateriet.milins.dao.IrFastighetDao;
                        import se.lantmateriet.milins.domain.inskrivning.IrFastighet;
                        
                        @Repository("irFastighetDao")
                        @SuppressWarnings("unchecked")
                        public class IrFastighetDaoEclipseLink extends GenericDaoEclipseLink<IrFastighet>
                        		implements IrFastighetDao {
                        
                        	@Override
                        	public List<IrFastighet> getIrFastighetByFnr(String fnr)
                        			throws DataAccessException {
                        		List<IrFastighet> lists = this.entityManager
                        				.createQuery(
                        						"select irFastigheter from IrFastighet irFastigheter where irFastigheter.fnr = :fnr")
                        				.setParameter("fnr", fnr).getResultList();
                        		// if (lists == null || lists.size() <= 0)
                        		// throw new EntityNotFoundException("Ingen IrFastighet med fnr = "
                        		// + fnr + " finns!");
                        		return lists;
                        	}
                        
                        	@Override
                        	public IrFastighet getIrFastighetByFnrAndVersion(String fnr, int version) {
                        		List<IrFastighet> lists = this.entityManager
                        				.createQuery(
                        						"select irFastigheter from IrFastighet irFastigheter where irFastigheter.fnr = :fnr and irFastigheter.version = :version")
                        				.setParameter("version", version).setParameter("fnr", fnr)
                        				.getResultList();
                        
                        		if (lists == null || lists.size() <= 0)
                        			return null;
                        		// throw new EntityNotFoundException("Ingen IrFastighet med fnr = "
                        		// + fnr + " och version = " + version + " finns!");
                        		return lists.get(0);
                        	}
                        
                        	@Override
                        	public void saveAll(List<IrFastighet> list) throws DataAccessException {
                        		for (IrFastighet irFastighet : list) {
                        			this.save(irFastighet);
                        		}
                        	}
                        
                        	@Override
                        	public int getLatestAvailableVersionOfIrFastighet(String fnr) {
                        
                        		List<Integer> lists = this.entityManager
                        				.createQuery(
                        						"select max(irf.version) from IrFastighet irf where irf.fnr = :fnr")
                        				.setParameter("fnr", fnr).getResultList();
                        
                        		if (lists == null || lists.size() <= 0)
                        			return 0;
                        		return lists.get(0) == null ? 0 : lists.get(0);
                        	}
                        
                        }

                        Comment


                        • #13
                          You use both @Autowired and @Resource on your entitymanager...

                          Code:
                          @Autowired
                          @Resource(mappedName = "milinsEntityManager")
                          protected EntityManager entityManager;
                          Don't... Use @PersistenceContext instead or use either one both not both...

                          Comment


                          • #14
                            Originally posted by Marten Deinum View Post
                            You use both @Autowired and @Resource on your entitymanager...

                            Code:
                            @Autowired
                            @Resource(mappedName = "milinsEntityManager")
                            protected EntityManager entityManager;
                            Don't... Use @PersistenceContext instead or use either one both not both...
                            Thanks alot Marten!
                            I used

                            Code:
                            @PersistenceContext(unitName = "milins-domain")
                            protected EntityManager entityManager;
                            and it works.
                            Thanks for all your time you spend to help me :-)

                            Comment

                            Working...
                            X