我正在使用Spring和struts并且在'/META-INF/context.xml'中有以下条目
I'm using Spring and struts and have the following entry in '/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>是否可以通过以下方式实施,
Is it possible to implement in the following way,
<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有以下内容,
My applicationContext.xml has got the following,
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/jdbc/xxx" /> </bean>我想从属性文件中获取jdbc.username和jdbc.pwd的值。 / p>
I want to pick up the values of jdbc.username and jdbc.pwd from a properties file.
推荐答案使用Spring的PlaceholderPropertyConfigurer(它只能替换Spring上下文中的值)是不可能的。
It's not possible using Spring's PlaceholderPropertyConfigurer (which only replaces values inside Spring context).
但是,可以使用 Ant ://ant.apache/manual/Tasks/replace.htmlrel =nofollow noreferrer>替换任务。类似于:
It is, however, possible using Ant during build process using Replace task. Something like:
<replace file="META-INF/context.xml" replacefilterfile="my.properties" />请注意,上述内容将属性名称作为要替换的标记 - 例如你需要在context.xml中使用jdbc.url而不是$ {jdbc.url}。如果绝对需要后者,则可以通过明确命名令牌替换为嵌套< replacefilter> 元素来实现。
Note that the above takes property names as tokens to be replaced - e.g. you'll need to use "jdbc.url" and not "${jdbc.url}" in your context.xml. If latter is absolutely required it can be achieved by explicitly naming tokens to be replaced as nested <replacefilter> elements.
更多推荐
是否可以在context.xml中使用占位符
发布评论