Spring 对外部文件中属性的访问在控制器中有效,但在域类中无效

Spring 对外部文件中属性的访问在控制器中有效,但在域类中无效,spring,spring-boot,Spring,Spring Boot,我在external application.properties文件中设置了一个属性,发现我可以在控制器中访问它,但不能在域类中访问它。我使用的是SpringBoot 1.1.9和groovy以及下面列出的代码片段 有人能解释一下我遗漏了什么吗 谢谢 --约翰 你能打印整个配置吗?你把@组件放在你的城市上,但它真的是由Spring管理的吗?如何创建它的实例?我认为它是通过主类中使用的@ComponentScan注释创建的。 //Application class used to startup

我在external application.properties文件中设置了一个属性,发现我可以在控制器中访问它,但不能在域类中访问它。我使用的是SpringBoot 1.1.9和groovy以及下面列出的代码片段

有人能解释一下我遗漏了什么吗

谢谢

--约翰


你能打印整个配置吗?你把
@组件
放在你的
城市
上,但它真的是由Spring管理的吗?如何创建它的实例?我认为它是通过主类中使用的@ComponentScan注释创建的。
//Application class used to startup    
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

//Controller - property is injected
@RestController
class CityController {
    @Value( '${sample.property}' )
    String stringTemplate

   @RequestMapping(value = "/", method = RequestMethod.GET)
   public String index(HttpServletResponse response) {
       return String.format(stringTemplate, 'world')
   }
}

//Domain class - property does not seem to be injected
@Component
public class City {
    @Value( '${sample.property}' )
    String stringTemplate

    String toString() {
        return String.format(stringTemplate, 'world')
    }
}