大家好我直接说到了
我像这样配置了我的server.xml
<GlobalNamingResources>
<Resource name="jdbc/MCDataSource"
global="jdbc/MCDataSource"
auth="Container"
type="javax.sql.DataSource"
username="AppDB"
password="AppDB"
url="jdbc:oracle:thin:@172.19.8.159:1521/OIM.itba.gov.in"
driverClassName="oracle.jdbc.OracleDriver"
initialSize="20"
maxWaitMillis="15000"
maxTotal="75"
maxIdle="20"
maxAge="7200000"
testOnBorrow="true"
validationQuery="select 1"
/>
</GlobalNamingResources>
我按照这个配置了我的context.xml
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<ResourceLink name="jdbc/MCDataSource"
global="jdbc/MCDataSource"
auth="Container"
type="javax.sql.DataSource" />
</Context>
和我的web.xml
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/MCDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
这是我获取连接的代码。
DataSource dataSource=null;
try {
Context initContext=new InitialContext();
Context context= (Context)initContext.lookup("java:/comp/env");
dataSource=(DataSource)context.lookup("jdbc/MCDataSource");
Connection connection=dataSource.getConnection();
} catch (NamingException e) {
e.printStackTrace();
}
catch (SQLException e) {
e.printStackTrace();
}
在调用此代码时,我遇到了异常 这是我的异常堆栈跟踪
javax.naming.NameNotFoundException: Name [com/env/jdbc/MCDataSource] is not bound in this Context. Unable to find [com].
at org.apache.naming.NamingContext.lookup(NamingContext.java:819)
at org.apache.naming.NamingContext.lookup(NamingContext.java:167)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:156)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.tcs.controller.BpmController.run(BpmController.java:56)
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)
可以告诉我,我在这里做错了什么。