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下,确保资源文件中的占位符没有被替换成配置文件中的值



posted @ 2016-03-10 13:33  uwannerme  阅读(1308)  评论(0编辑  收藏  举报