Spring @Autowired and @Value on property not working
问题 I would like to use @Value on a property but I always get 0 (on int). But on a constructor parameter it works. Example: @Component public class FtpServer { @Value("${ftp.port}") private int port; public FtpServer(@Value("${ftp.port}") int port) { System.out.println(port); // 21, loaded from the application.properties. System.out.println(this.port); // 0??? } } The object is spring managed, else the constructor parameter wouldn't work. Does anyone know what causes this weird behavior? 回答1: