Datasource is not bound properly to war appllication

时间:2015-09-01 22:30:02

标签: cdi spring-data-jpa

In my environment I have JSF 2.2 + CDI + Spring 4 + Wildfly 9 + Spring Data In wildfy server, I have two datasources configured:

  • ExampleDS (this comes from factory)
  • OracleDS (This one I created)

in persitence.xml, I have:

<persistence-unit name="persistenceUnit">
    <class>co.EntityClass</class>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
            <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" />
        </properties>
</persistence-unit>

My applicationContext.xml:

http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">

<context:component-scan base-package="co.com.dao, co.com.service.impl" />


<bean id="persistenceContext" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:/XXXXXDS"/>
</bean>


<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="persistenceContext" />
<property name="persistenceUnitName" value="persistenceUnit" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    </property>

</bean>  

<jpa:repositories base-package="co.com.psl.connectnetwork.dao" entity-manager-factory-ref="entityManagerFactory" />

whey I deploy my application, and I try to do a query in database, I get: Caused by: org.h2.jdbc.JdbcSQLException: Schema "XXXXXX" not found; SQL statement:

it looks like my application is taking the default datasource configured in wildfly ExampleDS, and that´s why it does not find the object I query, but why ?

I am not sure if cdi + spring + jsf is a good match

1 个答案:

答案 0 :(得分:0)

我不知道为什么,但我在applicationContext.xml的数据源定义中添加了这些属性:

<property name="lookupOnStartup" value="true"/>
<property name="proxyInterface" value="javax.sql.DataSource"/>