【发布时间】:2015-10-05 08:52:12
【问题描述】:
如何在 tomcat 的配置中设置简单的字符串值,然后在 java 应用程序中读取?
context.xml
<ResourceLink name="global/test" global="testing" type="java.lang.String" />
服务器.xml
<Enviroment name="testing" value="myUser" type="java.lang.String"/>
应用程序中的 web.xml
<resource-env-ref>
<resource-env-ref-name>global/test</resource-env-ref-name>
<resource-env-ref-type>java.lang.String</resource-env-ref-type>
</resource-env-ref>
在我的 java 应用程序中
public String getValue(){
return new JndiDataSourceLookup().getDataSource("global/test").toString();
}
当我运行 tomcat 时,我看到这些错误...
org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'global/test'; nested exception is javax.naming.NameNotFoundException: Name [global/test] is not bound in this Context. Unable to find [global].
javax.naming.NameNotFoundException: Name [global/test] is not bound in this Context. Unable to find [global].
【问题讨论】: