我有一个简单的RestController
:
@RestController
@PropertySource("classpath:application.properties")
public class Word2VecRestController {
private final static Logger LOGGER = Logger.getLogger(Word2VecRestController.class);
// @Resource is not working as well
@Autowired
Environment env;
// This is working for some reason
// but it's null inside the constructor
@Value("${test}")
String test;
public Word2VecRestController() {
LOGGER.info(env.getProperty("test"));
System.out.println("");
}
@GetMapping("/dl4j/getWordVector")
public ResponseEntity<List<Double[]>> getWordVector(String word) {
return null;
}
}
问题是env
总是为null
。我曾经看到过可以尝试使用@Resource
而不是@Autowired
,但这没有帮助。
application.properties:
test=helloworld
我尝试过使用
@Value("${test}")
String test;
但问题在于,这些在我需要它们构建对象期间是null
。
@PropertySource
,仅供测试。 - JosWord2VecRestController
是否定义了它? - Stefan Falknull
,就像使用@Value
声明的任何内容一样? - Stefan Falknull
。 - Stefan Falk