Circular placeholder reference 'jdbc.driverClassName' in property definitions

来源:互联网 发布:linux 下载整个文件夹 编辑:程序博客网 时间:2024/06/05 16:20
  • 在maven 多个module 开发时,父pom中定义字段,子pom或者properties引用,出现Circular placeholder reference 循环引用的问题。

解决方法:在项目上右键选properties,选择Deployment Assembly,删除src/main/resources选项。

设置

原因:参考http://virgoooos.iteye.com/blog/351737
maven在编译后能够正确的替换变量,eclipse在部署的时候,会将src/main/resources文件覆盖回来。造成循环引用。如果删除deploy assembly 中src/main/resources选项,则在部署时候会忽略resources文件夹。

下面举例:
parent.pom分别定义测试和生产环境的switch变量,
子项目中properties引用parent.pom 的switch变量
子项目中xml中应用properties的switch变量

parent.pom

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">    <modelVersion>1.0.0</modelVersion>    <groupId>com.test</groupId>    <artifactId>fms-parent</artifactId>    <version>0.0.1-SNAPSHOT</version>    <packaging>pom</packaging>    <name>fms-parent</name>    <!-- 预定义版本号 -->    <properties>        <spring.version>5.0</spring.version>    </properties>    <!-- 依赖预定义,子项目不依赖不生效 -->    <dependencyManagement>        <dependencies>            <dependency>                <groupId>org.springframework</groupId>                <artifactId>spring-core</artifactId>                <version>${spring.version}</version>            </dependency>        </dependencies>    </dependencyManagement>    <build>        <!--替换子项目的文件 -->        <resources>            <resource>                <directory>src/main/resources</directory>                <includes>                    <include>**/*.properties</include>                </includes>                <filtering>true</filtering>            </resource>        </resources>        <testResources>            <testResource>                <directory>src/test/resources</directory>                <includes>                    <include>**/*.properties</include>                </includes>                <filtering>true</filtering>            </testResource>        </testResources>        <plugins>            <!-- 定义插件 -->            <plugin>            </plugin>        </plugins>    </build>    <profiles>        <profile>               <!-- 测试环境,定义相关的属性 -->            <id>test</id>            <properties>                <jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>                <switch>false</switch>                </properties>        </profile>        <profile>            <!-- 生产环境,定义相关的属性 -->            <id>product</id>            <properties>                <jdbc.driver>com.oracle.jdbc.Driver</jdbc.driver>                       <switch>true</switch>            </properties>        </profile>      </profiles></project>

子项目application.properties

switch=${switch}

子项目application.xml

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans">    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>        <property name="ignoreResourceNotFound" value="true"/>        <property name="locations">            <list>                <value>classpath:application.properties</value>                <value>classpath:*.properties</value>            </list>        </property>    </bean>    <bean id="testBean" class="com.test">        <property name="switch" value="${switch}"></property>    </bean></beans>
0 0