我希望集中访问我的所有属性值,以便我可以做一些事情,比如确保所有内容都使用相同的属性名称,相同的默认值等.我已经创建了一个类来集中所有这些,但是我不确定需要访问这些值的类应该如何获取它们,因为您无法自动装配字符串.
我的班级是这样的:
@Configuration
public class SpringConfig {
@Autowired
@Value("${identifier:asdf1234}")
public String identifier;
}
Run Code Online (Sandbox Code Playgroud)
我可以在多个班级中使用它
public class Foo {
@Autowired
private String theIdentifier;
}
public class Bar {
@Autowired
private String anIdentifier;
}
Run Code Online (Sandbox Code Playgroud) 假设我有一个像这样的参数化测试:
@ParameterizedTest
@ValueSource(strings = {"a", "B", "r"})
void test1(String val) {
assertNotNull(val);
}
Run Code Online (Sandbox Code Playgroud)
我想做的只是针对一个值运行测试。有办法做到吗?我知道如何运行单独的测试,但如果有一种符号可以仅运行一个参数,那将会有所帮助。希望通过 Maven 运行它。
我正在尝试使用Eclipse Luna调试我的Maven webapp项目以在Tomcat 8中启动它.不幸的是,在尝试将其部署到Tomcat时,资源过滤期间的构建时间戳没有得到解决.Eclipse构建的WAR文件已解决,但它部署到Tomcat(通过"在服务器上运行"选项)不会.
在我的pom.xml中,我得到了:
<properties>
<timestamp>${maven.build.timestamp}</timestamp>
</properties>
<build>
<finalName>rapid-installer</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
Run Code Online (Sandbox Code Playgroud)
在一个属性文件中,我有
build.date=${timestamp}
Run Code Online (Sandbox Code Playgroud)