我有这种奇怪的行为使用Maven <filter>
标签和Spring配置。我的理解是Spring配置是Maven的普通XML文件,但是我遇到了<context:component-scan base-package="com.xyz"/>
标签的问题。测试XML文件如下所示
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"
default-autowire="byName">
<!-- Import the DataSource configurations -->
<import resource="classpath:spring/MyDataSource.xml"/>
<!-- Property File location -->
<context:property-placeholder location="${ext.properties.dir}"/>
<!--The services are auto-detected POJOs labeled with the @Service annotation.-->
<context:component-scan base-package="com.xyz"/>
</beans>
和Maven配置文件配置如下
<build>
.....
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>src/main/resources/build/build-${environment}.properties</filter>
</filters>
</build>
<profiles>
<profile>
<id>uat</id>
<activation>
<property>
<name>env</name>
<value>uat</value>
</property>
</activation>
<properties>
<environment>uat</environment>
</properties>
</profile>
<profile>
<id>prod</id>
<activation>
<property>
<name>env</name>
<value>prod</value>
</property>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<environment>prod</environment>
</properties>
</profile>
</profiles>
build-dev.properties的内容是
ext.properties.dir=file:///C:/Temp/myProp.properties
我的问题是Maven配置文件过滤无法正常工作,并且在打包过程中没有替换属性${ext.properties.dir}
。当我删除<context:component-scan base-package="com.xyz"/>
标签时,它表示工作,因此我把它放在需要过滤的属性下面。现在一切正常。我的问题是<context:component-scan base-package="com.xyz"/>
的问题是什么?
答案 0 :(得分:4)
我不认为<context:component-scan base-package="com.xyz"/>
而是上面的评论
<!--The services are auto-detected POJOs labeled with the @Service annotation.-->
@
在maven fitlers中有特殊含义。
说实话,我觉得Spring配置文件和maven过滤器之间的语法有很多重叠,可以一起使用它们。我的解决方案&#34;是为弹簧配置使用(尽可能长)两个文件。