我正在使用 Spring 和 struts,并在“/META-INF/context.xml”中有以下条目
<Context cachingAllowed="false" useHttpOnly="true">
<Resource name="jdbc/xxx" auth="Container" type="javax.sql.DataSource"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
maxActive="100" maxIdle="30" maxWait="10000"
username="xxxxx" password="xxxxx"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://xxx:1433;databaseName=xxx;"/>
</Context>
是否可以通过以下方式实现,
<Context cachingAllowed="false" useHttpOnly="true">
<Resource name="jdbc/xxx" auth="Container" type="javax.sql.DataSource"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
maxActive="100" maxIdle="30" maxWait="10000"
username="${jdbc.username}" password="${jdbc.pwd}"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="${jdbc.url}"/>
</Context>
我的 applicationContext.xml 有以下内容,
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/xxx" />
</bean>
我想从属性文件中获取 jdbc.username 和 jdbc.pwd 的值。