是否可以在context.xml中使用占位符

编程入门 行业动态 更新时间:2024-10-24 10:14:59
本文介绍了是否可以在context.xml中使用占位符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用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中使用占位符

本文发布于:2023-10-23 06:03:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1520008.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:context   xml

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!