spring-explicit bean示例化没有设置@value属性

yftpprvb  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(273)

我想要一张Map @Component 同一类的示例。我初始化示例如下:

applicationContext.getBean(TorrentService.class)

Torrent服务如下所示:

@Component
public class TorrentService {

    @Autowired
    private SimpMessagingTemplate template;

    @Autowired
    private TorrentRepository repository;

    private BtClient client;

    @Value("${refreshInterval}")
    private int interval;

...

全部 @Autowired 属性已初始化,属性除外 interval .
当我初始化的示例时 TorrentService 使用 @Autowired 财产 interval 设置正确。应该设置为 1000 相反,它被设置为 0 .

application.properties:

refreshInterval=1000

是因为 applicationContext.getBean 在国际奥委会之外吗?
有什么办法?

7cwmlq89

7cwmlq891#

你应该使用

@Value("#{refreshInterval}")

相关问题