Maven Profile标签

Maven Profiles标签可以针对不同的环境来使用不同的配置文件
在发布的时候可以用

  1. mvn release -p product
  2. mvn release -p test
  3. mvn release -p dev


默认本地deploy的时候用的是dev的配置 文件

在编译项目的过程中,资源中的占位符${}会被替换成配置文件中的值,如果没有进行替换,则会出现问题。


<profiles>
		<profile>
			<id>product</id>
			<build>
				<filters>
					<filter>src/main/resources/release.properties</filter>
				</filters>
			</build>
		</profile>
		<profile>
			<id>dev</id>
			<activation>
				<activeByDefault>true</activeByDefault>
			</activation>
			<build>
				<filters>
					<filter>src/main/resources/dev.properties</filter>
				</filters>
			</build>
		</profile>
		<profile>
			<id>test</id>
			<build>
				<filters>
					<filter>src/main/resources/test.properties</filter>
				</filters>
			</build>
		</profile>
	</profiles>

如果编译时资源文件中的占位符没有被替换成配置文件中的值,则一般会抛出异常:

Circular placeholder reference 'db.url' in property definitions
        at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209)
        at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:220)
        at com.showjoy.core.configure.SecPropertyPlaceholderConfigurer.processProperties(SecPropertyPlaceholderConfigurer.java:50)
        at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:84)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:656)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5003)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5517)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1095)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1960)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)


这时的处理办法是,把target中编译好的文件clean掉,重新用maven build下,确保资源文件中的占位符没有被替换成配置文件中的值



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值