Eclipse mvn 项目报错:Circular placeholder reference 'jdbc.driverClassName' in property definitions

  • 在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>

文章来源:https://blog.csdn.net/my_flash/article/details/52326454



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值