0
org.springframework.beans.factory.BeanCreationException:創建名爲'cpDataSource'的bean時出錯:init方法的調用失敗;嵌套0例外是javax.naming.NameNotFoundException:JDBC/FCjavax.naming.NamingNotFoundException:jdbc/fc
我使用wildfly 10和這裏的web.xml。
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<context-param id="ParamValue_1395228155626">
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
<resource-ref>
<description>Oracle example</description>
<res-ref-name>jdbc/fc</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<servlet id="Init">
<servlet-name>Init Servlet</servlet-name>
<servlet-class>com.cedar.cp.utc.common.InitServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>reviewbudget</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>9</load-on-startup>
</servlet>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
</web-app>
這context.xml的
<?xml version='1.0' encoding='utf-8'?>
<Context crossContext="true" reloadable="true">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="java:jboss/jdbc/fc" auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@127.0.0.1:1521:orcl"
username="C##user" password="windows7password" maxActive="20" maxIdle="10"
maxWait="-1"/>
</Context>
這裏的applicationContext.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" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<jee:jndi-lookup id="cpDataSource" jndi-name="java:jboss/jdbc/fc"
expected-type="javax.sql.DataSource" />
<jee:jndi-lookup id="oaDataSource" jndi-name="java:jboss/jdbc/fc"
expected-type="javax.sql.DataSource" />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="cpDataSource" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"/>
<property name="username" value="C##user1"/>
<property name="password" value="windows7password"/>
</bean>
</beans>
我怎樣才能解決這個問題? 謝謝。
我不知道了很多關於春天,但'context.xml'一個Tomcat的事情? WildFly肯定不會尋找'context.xml'。 –
感謝您的回覆,但wildfly現在正確查找context.xml。 –