Announcement Announcement Module
Collapse
No announcement yet.
Issue with entityManagerFactory after upgrading from 3.12 to 3.1.4 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue with entityManagerFactory after upgrading from 3.12 to 3.1.4

    Note: 3.1.3 is also affected, but my config worked in 3.1.2.

    I get an error

    No unique bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: [dataSource, mainDataSource]

    Yes, i have 2 dataSources but 1 is a LazyConnectionDataSourceProxy and this worked in 3.1.2. (see config and stack trace below. Note: Couldnot post full stack trace, else text was too long...).

    The stack trace also claims:

    Error creating bean with name 'entityManagerFactory' defined in class path resource [ApplicationContext.xml]: Unsatisfied dependency expressed through bean property 'jtaDataSource':
    However I do not use JTA and it is never mentioned anywhere in the whole config file. So this is pretty confusing why this appears at all.

    Any ideas how I can solve this?

    <bean id="entityManagerFactory" autowire="autodetect"
    class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="myPackage.entity" />
    <property name="jpaVendorAdapter">
    <bean class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
    <property name="showSql" value="true" />
    <property name="generateDdl" value="false" />
    <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQL82Dialect" />
    </bean>
    </property>
    <property name="jpaProperties">
    <props>
    <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
    <prop key="hibernate.id.new_generator_mappings">true</prop>
    <prop key="hibernate.cache.use_second_level_cache">true</prop>
    <prop key="hibernate.cache.region.factory_class">org.hib ernate.cache.ehcache.EhCacheRegionFactory</prop>
    </props>
    </property>
    </bean>

    <!-- DataSource Configuration -->
    <!-- Tell Spring to bounce off BoneCP -->
    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.LazyCon nectionDataSourceProxy">
    <property name="targetDataSource">
    <ref local="mainDataSource" />
    </property>
    </bean>

    <!--BoneCP configuration -->
    <bean id="mainDataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
    <property name="driverClass" value="org.postgresql.Driver" />
    <property name="jdbcUrl" value="#{'jdbcostgresql://${database.host}:${database.port}/${database.name}'}" />
    <property name="username" value="${database.username}"/>
    <property name="password" value="${database.password}"/>
    <property name="idleConnectionTestPeriod" value="60"/>
    <property name="IdleMaxAgeInMinutes" value="4"/>
    <property name="maxConnectionsPerPartition" value="60"/>
    <property name="minConnectionsPerPartition" value="10"/>
    <property name="partitionCount" value="5"/>
    <property name="acquireIncrement" value="10"/>
    <property name="statementsCacheSize" value="50"/>
    </bean>

    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExc eptionTranslationPostProcessor#0': Initialization of bean failed;

    ...

    Caused by: org.springframework.beans.factory.UnsatisfiedDepen dencyException: Error creating bean with name 'entityManagerFactory' defined in class path resource [ApplicationContext.xml]: Unsatisfied dependency expressed through bean property 'jtaDataSource': : No unique bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: [dataSource, mainDataSource]; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: [dataSource, mainDataSource]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireByType(Abstract AutowireCapableBeanFactory.java:1199) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1091) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 94) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:225) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:291 ) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeansOfType(DefaultListableB eanFactory.java:420) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.beans.factory.BeanFactoryUtils .beansOfTypeIncludingAncestors(BeanFactoryUtils.ja va:277) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.dao.support.PersistenceExcepti onTranslationInterceptor.detectPersistenceExceptio nTranslators(PersistenceExceptionTranslationInterc eptor.java:139) ~[spring-tx-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.dao.support.PersistenceExcepti onTranslationInterceptor.<init>(PersistenceExcepti onTranslationInterceptor.java:79) ~[spring-tx-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.dao.annotation.PersistenceExce ptionTranslationAdvisor.<init>(PersistenceExceptio nTranslationAdvisor.java:70) ~[spring-tx-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.dao.annotation.PersistenceExce ptionTranslationPostProcessor.setBeanFactory(Persi stenceExceptionTranslationPostProcessor.java:103) ~[spring-tx-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeAwareMethods(Abst ractAutowireCapableBeanFactory.java:1475) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1443) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:519) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    ... 44 common frames omitted
    Caused by: org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: [dataSource, mainDataSource]
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.doResolveDependency(DefaultList ableBeanFactory.java:824) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.resolveDependency(DefaultListab leBeanFactory.java:731) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireByType(Abstract AutowireCapableBeanFactory.java:1184) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]

  • #2
    Remove 'autowire="autodetect"'... YOu already expressed al dependencies... jtaDatasource was added and due to your autowiring configuration it tries to autowire by type (as the exception tells you).

    Comment

    Working...
    X