我遇到了@Autowiring为空的问题。我正在寻找建议如何模拟它的弹簧启动方式。
使用大量的Repository类,我的Soap-Services变得非常大。这给了我一个很大的@Autowired列表。现在,当我想调用像HeaderValidator.class这样的辅助类时,我无法实例化并将其称为POJO。这是因为我的HeaderValidator中注释@Autowiring的所有内容都为null。当我在第(1)行添加@Autowired并在SoapServiceImpl中删除(2)的内容时,我可以使它工作。 但这将以@Autowired注释字段的大量列表结束,这看起来很难看。我想要阻止它,即使它现在也可以。
This Article提到带有AspectJ的@Configurable。但该文章是从2013年开始的,Spring-Boot自此开始发展。我尝试了@Configurable解决方案,但它在我的情况下没有用。
如何通知我的SpringBoot-Application类副本? @ Configurable-way仍然是唯一的吗?或者我只是简单地将应用程序建模错误?
Application.class:
=OR(ISNUMBER(SEARCH("foo";E1));ISNUMBER(SEARCH("egg";E1)))
SoapService.class(在Application.class中调用publishSoapServices()时发布):
@SpringBootApplication
public class Application {
private static ApplicationContext ctx;
public static void main(String... args) {
ctx = SpringApplication.run(Application.class, args);
publishSoapServices();
}
我的问题类:
public class SoapServiceImpl implements SoapService {
@Autowired
ProjectRepository projectRepo;
(1) "@Autowired"
HeaderValidator headerValidator;
@Override
public EventReport send(@WebParam(name = "header") HeaderType headerType,
@WebParam(name = "content") ContentType contentType) {
return storeServiceData(headerType, messageType);
}
private EventReport storeServiceData(HeaderType headerType, ContentType contentType) {
projectRepo.save(contentType);
(2) "HeaderValidator headerValidator= new HeaderValidator()"
return headerValidator.validate(headerType);
}
答案 0 :(得分:1)
我设法解决了我的问题。这只是因为糟糕的设计。我通过应用程序并正确配置了@Configurable
。现在一切正常。感谢M.Deinum!