Circular placeholder reference 'jdbc.driverClassName' in property definitions

11666 ワード

  • mavenの複数のmoduleの開発時に、親pomでフィールド、子pomまたはproperties参照を定義すると、Circular placeholder referenceループ参照の問題が発生します.

  • 解決方法:プロジェクトでpropertiesを右クリックし、Deployment Assemblyを選択し、src/main/resourcesオプションを削除します.
    设置
    理由:参考http://virgoooos.iteye.com/blog/351737mavenはコンパイル後に変数を正しく置き換えることができ、eclipseは配置時にsrc/main/resourcesファイルを上書きします.循環参照を作成します.deploy assemblyのsrc/main/resourcesオプションを削除すると、デプロイ時にresourcesフォルダは無視されます.
    次に例を挙げます.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>

    サブプロジェクトアプリケーションproperties
    switch=${switch}

    サブプロジェクトアプリケーション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>