构造函数中使用Spring @Value注解
小于 1 分钟
构造函数中使用Spring @Value注解
如果想在构造函数中使用的@value
注解的话,demo如下:
// File: sample/Message.groovy
package sample
import org.springframework.beans.factory.annotation.*
import org.springframework.stereotype.*
@Component
class Message {
final String text
// Use @Autowired to get @Value to work.
@Autowired
Message(
// Refer to configuration property
// app.message.text to set value for
// constructor argument message.
@Value('${app.message.text}') final String text) {
this.text = text
}
}
版权申明
本站点所有内容,版权均归https://wenchao.ren所有,除非明确授权,否则禁止一切形式的转载协议
打赏
