我Maven的配置看起来像春:不能读取行家
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<systemProperties>
<spring.active.profiles>development</spring.active.profiles>
</systemProperties>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
和我有试图将其值设置
import javax.annotation.Nonnull;
import org.springframework.beans.factory.annotation.Value;
public class PropertyReader {
@Value("${spring.active.profiles}")
private String profile;
@Nonnull
public String getProfile() {
return profile;
}
}
我尝试测试它作为一个类
public class PropertyReaderTest {
@Test
public void testGetProfile() throws Exception {
assertEquals("development", new PropertyReader().getProfile());
}
}
我看到测试失败的
Failed tests: testGetProfile(com.org.myproj.external_services.ifs.PropertyReaderTest): expected:<development> but was:<null>
这是什么我在这里失踪?
UPDATE
我看到属性被设置Maven的
@Test
public void testGetProfile() throws Exception {
System.out.printf(System.getProperty("spring.active.profiles"));
assertEquals("development", new PropertyReader().getProfile());
}
我看到
development
java.lang.AssertionError:
Expected :development
Actual :null
我甚至尝试了不同的语法
public class PropertyReader {
// @Value("#{systemProperties[spring.active.profiles]")
@Value("${spring.active.profiles")
private String profile;
@Nonnull
public String getProfile() {
return profile;
}
}
但仍无法读取它