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.0modelVersion>
    <groupId>com.testgroupId>
    <artifactId>fms-parentartifactId>
    <version>0.0.1-SNAPSHOTversion>
    <packaging>pompackaging>
    <name>fms-parentname>

    
    <properties>
        <spring.version>5.0spring.version>
    properties>

    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-coreartifactId>
                <version>${spring.version}version>
            dependency>
        dependencies>
    dependencyManagement>

    <build>
        
        <resources>
            <resource>
                <directory>src/main/resourcesdirectory>
                <includes>
                    <include>**/*.propertiesinclude>
                includes>
                <filtering>truefiltering>
            resource>
        resources>

        <testResources>
            <testResource>
                <directory>src/test/resourcesdirectory>
                <includes>
                    <include>**/*.propertiesinclude>
                includes>
                <filtering>truefiltering>
            testResource>
        testResources>

        <plugins>
            
            <plugin>
            plugin>
        plugins>
    build>

    <profiles>
        <profile>   
            
            <id>testid>
            <properties>
                <jdbc.driver>com.mysql.jdbc.Driverjdbc.driver>
                <switch>falseswitch>
                properties>
        profile>

        <profile>
            
            <id>productid>
            <properties>
                <jdbc.driver>com.oracle.jdbc.Driverjdbc.driver>       
                <switch>trueswitch>
            properties>
        profile>  
    profiles>
project>

子项目application.properties

switch=${switch}

子项目application.xml


<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.propertiesvalue>
                <value>classpath:*.propertiesvalue>
            list>
        property>
    bean>

    <bean id="testBean" class="com.test">
        <property name="switch" value="${switch}">property>
    bean>
beans>

你可能感兴趣的:(java)