下面显示的是一段代码,我尝试引用我的ApplicationProperties bean.当我从构造函数引用它时它是null,但是当从另一个方法引用它时它很好.到目前为止,我在其他类中使用这个自动装配的bean没有任何问题.但这是我第一次尝试在另一个类的构造函数中使用它.
在下面的代码片段中,当从构造函数调用时,applicationProperties为null,但在convert方法中引用时则不是.我错过了什么
@Component
public class DocumentManager implements IDocumentManager {
private Log logger = LogFactory.getLog(this.getClass());
private OfficeManager officeManager = null;
private ConverterService converterService = null;
@Autowired
private IApplicationProperties applicationProperties;
// If I try and use the Autowired applicationProperties bean in the constructor
// it is null ?
public DocumentManager() {
startOOServer();
}
private void startOOServer() {
if (applicationProperties != null) {
if (applicationProperties.getStartOOServer()) {
try {
if (this.officeManager == null) {
this.officeManager = new DefaultOfficeManagerConfiguration()
.buildOfficeManager();
this.officeManager.start();
this.converterService = new …
Run Code Online (Sandbox Code Playgroud)