@Component
public class TrackCoach implements Coach {
private int integerVal;
}
当我使用XML配置时,我过去很容易做类似的事情:
<property name="integerVal" value="174"/>
如何通过注释实现某些目标?
答案 0 :(得分:0)
您可以使用@Value,请检查此link
答案 1 :(得分:0)
@Component
public class TrackCoach implements Coach {
@Value("${integerVal}")
private int integerVal;
}
这会将值注入该变量。
在application.properties
文件中
在
integerVal=174
答案 2 :(得分:0)
您可以在属性文件中添加属性,例如
yourIntegerValue=12345
您可以使用此属性,如
@Component
public class TrackCoach implements Coach {
@Value("${yourIntegerValue}")
private int integerVal;
}