栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Maven和Spring控制项目:如何使用Maven配置文件设置Spring配置文件?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Maven和Spring控制项目:如何使用Maven配置文件设置Spring配置文件?

使用从这两个答案中获得的知识以及我的研究,我能够得到一个由pom控制的开发/生产系统,该系统可以设置正确的数据库值。

首先,在pom中,我创建了两个配置文件。

<!-- Production and Development Profiles --><profiles>    <!-- Nike profile needs go here -->    <profile>        <id>production</id>        <activation> <property>     <name>environment.type</name>     <value>prod</value> </property>        </activation>    </profile>    <!-- Catalyst profile needs go here -->    <profile>        <id>development</id>        <activation> <property>     <name>environment.type</name>     <value>dev</value> </property>        </activation>        <build> <!-- This holds the properties for the Spring context file.      Database values will be changes to development. --> <filters>     <filter>src/main/resources/dev.database.properties</filter> </filters> <resources>     <!-- This is the directory that holds the Spring context          file.  The entire folder is searched, so either no          other file should have place holders or you should          exclude other files from being filtered. -->     <resource>         <directory>src/main/webapp/WEBINF/</directory>         <filtering>true</filtering>     </resource> </resources>    </profile></profiles>

在servlet-context.xml中的WEBINF目录中,放置了占位符:

<!-- For database, uses maven filtering to fill in placeholders --><bean id="dataSource"  destroy-method="close">    <property name="driverClassName" value="${db.driver}" />    <property name="url"  value="${db.url}" />    <property name="username"        value="${db.username}" />    <property name="password"        value="${db.password}" />    <property name="maxActive">        <value>10</value>    </property>    <property name="maxIdle">        <value>1</value>    </property></bean>

然后我创建了一个属性文件,该文件位于src / main / resources中

## Development database properties file#db.driver=oracle.jdbc.driver.OracleDriverdb.url=jdbc:oracle:thin:[USER/PASSWORD]@[HOST][:PORT]:SIDdb.username=jsmithdb.password=s3cr3t

然后我可以用

mvn -P developement clean install

或有一个settings.xml可以为我设置正确的配置文件:

<settings>  <profiles>    <profile>      <activation>        <activeByDefault>true</activeByDefault>      </activation>      <properties>        <environment.type>dev</environment.type>      </properties>    </profile>  </profiles>   </settings>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/391566.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号