Is it possible to use placeholder in context.xml

前端 未结 2 1943
星月不相逢
星月不相逢 2021-01-13 17:20

I\'m using Spring and struts and have the following entry in \'/META-INF/context.xml\'




        
相关标签:
2条回答
  • 2021-01-13 17:57

    It's not possible using Spring's PlaceholderPropertyConfigurer (which only replaces values inside Spring context).

    It is, however, possible using Ant during build process using Replace task. Something like:

    <replace file="META-INF/context.xml" replacefilterfile="my.properties" />
    

    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.

    0 讨论(0)
  • 2021-01-13 17:59

    For Tomcat, you can setup a connection pool in the server's server.xml file, that way the username/password is outside of your war file. Here's some info on how Context elements behave in Tomcat 5.5 http://tomcat.apache.org/tomcat-5.5-doc/config/context.html

    Alternately, you can use the standalone DBCP package from Apache from your Spring config file, and use the jdbc.properties to replace your username/password in there. For example:

    <context:property-placeholder location="jdbc.properties"/>
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
      <property name="driverClassName">
        <value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value>
      </property>
      <property name="url">
        <value>${jdbc.url}</value>
      </property>
      <property name="username">
        <value>${jdbc.username}</value>
      </property>
      <property name="password">
        <value>${jdbc.password}</value>
      </property>
      <property name="initialSize">
        <value>30</value>
      </property>
      <property name="maxActive">
        <value>100</value>
      </property>
      <property name="maxWait">
        <value>10000</value>
      </property>
    </bean>
    
    0 讨论(0)
提交回复
热议问题