Spring 无法从其他模块读取属性

Spring 无法从其他模块读取属性,spring,module,properties,javabeans,Spring,Module,Properties,Javabeans,我正在创建一个基于两个模块的项目:服务和web 在服务中,我正在使用web模块中定义的属性注入bean。属性取决于web模块中定义的配置文件 在jetty start上,显示了一个spring错误,通知我他无法读取属性,因此无法实例化bean 那个么,如何在web模块中声明属性并在服务模块中使用它们呢 在服务模块中,我正在注入一个bean,它使用在另一个模块中声明的属性 <bean id="universignService" class="fr.lfm.dna.service.file

我正在创建一个基于两个模块的项目:服务和web

在服务中,我正在使用web模块中定义的属性注入bean。属性取决于web模块中定义的配置文件

在jetty start上,显示了一个spring错误,通知我他无法读取属性,因此无法实例化bean

那个么,如何在web模块中声明属性并在服务模块中使用它们呢

在服务模块中,我正在注入一个bean,它使用在另一个模块中声明的属性

<bean id="universignService" 
class="fr.lfm.dna.service.file.document.impl.UniversignServiceImpl"
    autowire="byName" init-method="initWebService" lazy-init="true">
<property name="url" value="${ws.universign.url}">
</property>
<property name="username" value="${dna.ws.universign.username}">
</property>
<property name="password" value="${dna.ws.universign.password}">
</property>
</bean>

据我所知,您有两个(ServiceProject和WebProject)maven项目。在ServiceProject中,您希望使用WebProject/pom.xml中的属性。问题是Spring对这个文件一无所知

如果要为多个项目共享这些属性,则选项很少

1) 我首先想到的是创建一个父maven项目。这将是一个只有一个pom.xml的项目,您可以在
properties
部分中定义您的属性

<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>4.0.0</modelVersion>

    <groupId>com.test</groupId>
    <artifactId>parent</artifactId>
    <version>1.0.SNAPSHOT</version>

    <properties>
        <dna.ws.universign.username>ABC</dna.ws.universign.username>
        <dna.ws.universign.password>XYZ</dna.ws.universign.password>
    </properties>
</project>

其中
spring config.xml
是一个文件,用于存储配置。在此之后,Spring可以注入属性。

您能否澄清一下,您所说的“模块”是什么意思?我想你是指Intellij IDEA项目模块。无论如何,您应该提供一个代码,将您的属性注入到bean中。这是一个maven eclipse项目。问题是,即使属性依赖于运行时环境:dev,prod。所以它必须位于pom.xml之外的过滤属性文件中。我想知道,您是否在该项目中使用Spring Boot?如果是这样,事情就会容易得多。
<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>4.0.0</modelVersion>

    <groupId>com.test</groupId>
    <artifactId>web</artifactId>

    <parent>
        <groupId>com.test</groupId>
        <artifactId>parent</artifactId>
        <version>1.0.SNAPSHOT</version>
    </parent
</project>
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>spring-config.xml</include>
            </includes>
        </resource>
    </resources>
  </build>