Announcement Announcement Module
Collapse
No announcement yet.
Error creating bean with name 'transactionManager' Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error creating bean with name 'transactionManager'

    Hi,

    I'm trying to build a runnable jar file with all depentencies. I use the onejar Plugin[1].
    But wenn i start it i get the following error:
    Code:
    java -jar '/home/axi/Documents/workspace-sts-2.6.1.RELEASE/AppDataDownload/target/AppDataDownload-0.1.0.BUILD-SNAPSHOT.one-jar.jar'
    Exception in thread "main" java.lang.reflect.InvocationTargetException
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:616)
    	at com.simontuffs.onejar.Boot.run(Boot.java:306)
    	at com.simontuffs.onejar.Boot.main(Boot.java:159)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in URL [file:/home/axi/Documents/workspace-sts-2.6.1.RELEASE/AppDataDownload/src/main/resources/META-INF/spring/applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [file:/home/axi/Documents/workspace-sts-2.6.1.RELEASE/AppDataDownload/src/main/resources/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to get the default Bean Validation factory
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    	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.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.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
    	at at.tugraz.iaik.appdatadownload.metadata.DownloadMetaData.main_aroundBody0(DownloadMetaData.java:45)
    	at at.tugraz.iaik.appdatadownload.metadata.DownloadMetaData.main(DownloadMetaData.java:1)
    	... 6 more
    My "Main" Class:
    Code:
    public static void main(String[] args) {
    		int maxIndex = 850;
    		ApplicationContext context = null;
    		context = new FileSystemXmlApplicationContext("file:/home/axi/Documents/workspace-sts-2.6.1.RELEASE/AppDataDownload/src/main/resources/META-INF/spring/applicationContext.xml");
    		MyApp app=new MyApp();
    ...
    }
    My applicationContext.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd         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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
       
        <context:property-placeholder location="file:/home/axi/Documents/workspace-sts-2.6.1.RELEASE/AppDataDownload/src/main/resources/META-INF/spring/*.properties"/> 
         <!--
          <context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>
    	-->
        <context:spring-configured/>
    
        <context:component-scan base-package="at.tugraz.iaik.appdatadownload">
            <context:exclude-filter expression=".*_Roo_.*" type="regex"/>
            <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
        </context:component-scan>
        <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
            <property name="driverClassName" value="${database.driverClassName}"/>
            <property name="url" value="${database.url}"/>
            <property name="username" value="${database.username}"/>
            <property name="password" value="${database.password}"/>
            <property name="testOnBorrow" value="true"/>
            <property name="testOnReturn" value="true"/>
            <property name="testWhileIdle" value="true"/>
            <property name="timeBetweenEvictionRunsMillis" value="1800000"/>
            <property name="numTestsPerEvictionRun" value="3"/>
            <property name="minEvictableIdleTimeMillis" value="1800000"/>
        </bean>
        <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory"/>
        </bean>
        <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
        <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
           <property name="persistenceUnitName" value="persistenceUnit"/>
           <property name="dataSource" ref="dataSource"/>
        </bean>
    
    </beans>
    My persistence.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <properties>
                <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
                <property name="hibernate.hbm2ddl.auto" value="create"/>
                <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
                <property name="hibernate.connection.charSet" value="UTF-8"/>
            </properties>
        </persistence-unit>
    </persistence>
    For me it looks like the persistence.xml is not found .. But why?

    Thanks,
    Alexander

    [1] http://onejar-maven-plugin.googlecode.com

  • #2
    The jar file AppDataDownload-0.1.0.BUILD-SNAPSHOT.one-jar.jar has this structure:
    Code:
    AppDataDownload-0.1.0.BUILD-SNAPSHOT.one-jar
    ├── com
    │** └── simontuffs
    │**     └── onejar
    │**         ├── Boot$1.class
    │**         ├── Boot$2.class
    │**         ├── Boot$3.class
    │**         ├── Boot.class
    │**         ├── Boot.java
    │**         ├── Handler$1.class
    │**         ├── Handler.class
    │**         ├── Handler.java
    │**         ├── IProperties.class
    │**         ├── IProperties.java
    │**         ├── JarClassLoader$1.class
    │**         ├── JarClassLoader$ByteCode.class
    │**         ├── JarClassLoader.class
    │**         └── JarClassLoader.java
    ├── lib
    │** ├── androidmarketapi-0.6.jar
    │** ├── antlr-2.7.6.jar
    │** ├── aopalliance-1.0.jar
    │** ├── aspectjrt-1.6.11.jar
    │** ├── aspectjweaver-1.6.11.jar
    │** ├── cglib-nodep-2.2.jar
    │** ├── commons-collections-3.1.jar
    │** ├── commons-dbcp-1.3.jar
    │** ├── commons-lang-2.1.jar
    │** ├── commons-pool-1.5.4.jar
    │** ├── dom4j-1.6.1.jar
    │** ├── flexjson-2.1.jar
    │** ├── hibernate-commons-annotations-3.2.0.Final.jar
    │** ├── hibernate-core-3.6.3.Final.jar
    │** ├── hibernate-entitymanager-3.6.3.Final.jar
    │** ├── hibernate-jpa-2.0-api-1.0.0.Final.jar
    │** ├── hibernate-validator-4.1.0.Final.jar
    │** ├── hsqldb-1.8.0.10.jar
    │** ├── javassist-3.12.0.GA.jar
    │** ├── jcl-over-slf4j-1.6.1.jar
    │** ├── jta-1.1.jar
    │** ├── log4j-1.2.16.jar
    │** ├── org.springframework.roo.annotations-1.1.4.RELEASE.jar
    │** ├── plexus-utils-1.1.jar
    │** ├── protobuf-java-2.2.0.jar
    │** ├── servlet-api-2.5.jar
    │** ├── slf4j-api-1.6.1.jar
    │** ├── slf4j-log4j12-1.6.1.jar
    │** ├── spring-aop-3.0.5.RELEASE.jar
    │** ├── spring-asm-3.0.5.RELEASE.jar
    │** ├── spring-aspects-3.0.5.RELEASE.jar
    │** ├── spring-beans-3.0.5.RELEASE.jar
    │** ├── spring-context-3.0.5.RELEASE.jar
    │** ├── spring-context-support-3.0.5.RELEASE.jar
    │** ├── spring-core-3.0.5.RELEASE.jar
    │** ├── spring-expression-3.0.5.RELEASE.jar
    │** ├── spring-jdbc-3.0.5.RELEASE.jar
    │** ├── spring-orm-3.0.5.RELEASE.jar
    │** ├── spring-test-3.0.5.RELEASE.jar
    │** ├── spring-tx-3.0.5.RELEASE.jar
    │** └── validation-api-1.0.0.GA.jar
    ├── main
    │** └── AppDataDownload-0.1.0.BUILD-SNAPSHOT.jar
    └── META-INF
        └── MANIFEST.MF
    AppDataDownload-0.1.0.BUILD-SNAPSHOT.jar:
    Code:
    ├── at
    │** └── tugraz
    │**     └── iaik
    │**         └── appdatadownload
    │**             ├── metadata
    │**             │** ├── DownloadMetaData$1.class
    │**             │** ├── DownloadMetaData$2.class
    │**             │** ├── DownloadMetaData.class
    │**             │** ├── DownloadMetaData_Roo_Configurable.class
    │**             │** ├── DownloadMetaData_Roo_Entity.class
    │**             │** └── DownloadMetaData_Roo_ToString.class
    │**             └── tools
    │**                 ├── AppVersion.class
    │**                 ├── AppVersion_Roo_Configurable.class
    │**                 ├── AppVersion_Roo_Entity.class
    │**                 ├── AppVersion_Roo_JavaBean.class
    │**                 ├── AppVersion_Roo_ToString.class
    │**                 ├── MyApp.class
    │**                 ├── MyApp_Roo_Configurable.class
    │**                 ├── MyApp_Roo_Entity.class
    │**                 ├── MyApp_Roo_JavaBean.class
    │**                 ├── MyApp_Roo_ToString.class
    │**                 ├── MyTools.class
    │**                 ├── MyTools_Roo_Configurable.class
    │**                 ├── MyTools_Roo_Entity.class
    │**                 ├── MyTools_Roo_ToString.class
    │**                 ├── Settings.class
    │**                 ├── Settings_Roo_Configurable.class
    │**                 ├── Settings_Roo_Entity.class
    │**                 └── Settings_Roo_ToString.class
    ├── builddef.lst
    ├── log4j.properties
    └── META-INF
        ├── aop-ajc.xml
        ├── MANIFEST.MF
        ├── maven
        │** └── at.tugraz.iaik.appdatadownload
        │**     └── AppDataDownload
        │**         ├── pom.properties
        │**         └── pom.xml
        ├── persistence.xml
        └── spring
            ├── applicationContext.xml
            ├── applicationContext.xmlCopy
            └── database.properties
    In STS it runs without any problem.

    Thanks,
    Alexander

    Comment


    • #3
      Hey Alex,

      I hate to resurrect an old thread, but I'm in the same now you were in 1.5 years ago... And I can't for the life of me find a solution.

      I'm trying to make a runnable Jar that can do DB connectivity.

      I'm wondering if you ever sorted this out?

      Here's my error:

      Exception in thread "main" java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoa der.main(JarRsrcLoader.java:58)
      Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'transactionManager' defined in class path resource [resources/META-INF/spring/applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in class path resource [resources/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No persistence unit with name 'persistenceUnit' found
      at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:328)
      at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:106)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1360)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1118)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
      at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 94)
      at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:225)
      at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:291 )
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:193)
      at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:585)
      at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:913)
      at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:464)
      at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:139)
      at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:83)
      at Main.initialiseApplicationContextFromJar(Main.java :14)
      at Main.main(Main.java:24)
      ... 5 more
      Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in class path resource [resources/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No persistence unit with name 'persistenceUnit' found
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1455)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:519)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
      at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 94)
      at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:225)
      at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:291 )
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:193)
      at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:322)
      ... 21 more
      Caused by: java.lang.IllegalArgumentException: No persistence unit with name 'persistenceUnit' found
      at org.springframework.orm.jpa.persistenceunit.Defaul tPersistenceUnitManager.obtainPersistenceUnitInfo( DefaultPersistenceUnitManager.java:535)
      at org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean.determinePersistenceUnitInfo(Loca lContainerEntityManagerFactoryBean.java:287)
      at org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean.createNativeEntityManagerFactory( LocalContainerEntityManagerFactoryBean.java:239)
      at org.springframework.orm.jpa.AbstractEntityManagerF actoryBean.afterPropertiesSet(AbstractEntityManage rFactoryBean.java:310)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1514)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1452)
      ... 28 more

      Comment


      • #4
        Ok some progress on this... If I add the following line to my applicationContext.xml, I can now get the persistence.xml to load from my jar file...

        Now the problem with persistenceUnit not found only happens inside Eclipse, but if I comment out that line it works in Eclipse but not outside... so at least I can use that to work around the issue, even if I can't finally solve it completely.

        Code:
        <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
        	<property name="persistenceXmlLocation" value="resources/META-INF/persistence.xml"/>
                <property name="persistenceUnitName" value="persistenceUnit"/>
                <property name="dataSource" ref="dataSource"/>
            </bean>

        Comment

        Working...
        X