【发布时间】:2015-11-12 06:49:29
【问题描述】:
我有一个使用 tomcat 作为容器的 spring 应用程序。 Tomcat 的 context.xml 有以下条目:
<Resource name="jdbc/DB" auth="Container" type="javax.sql.DataSource"
username="postgres" password=""
url="jdbc:postgresql://localhost:5432/postgres"
driverClassName="org.postgresql.Driver"/>
<Environment name="ws.url" type="java.lang.String" value="http://localhost:8088/" />
使用以下 xml 配置可以很好地加载资源:
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/DB" expected-type="javax.sql.DataSource" />
但我尝试使用以下 xml 配置加载环境变量:(这里我尝试将 ${url} 设置为 http://localhost:8088/",如 context.xml 文件中的设置)
<bean id="databaseprops" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties">
<bean class="java.util.Properties">
<constructor-arg>
<map>
<entry key="url">
<jee:jndi-lookup jndi-name="java:comp/env/ws.url"/>
</entry>
</map>
</constructor-arg>
</bean>
</property>
</bean>
但我收到以下错误:
javax.naming.NameNotFoundException: Name [ws.url] is not bound in this Context. Unable to find [ws.url].
任何想法我做错了什么?
【问题讨论】: