在使用new关键字创建的对象中自动关联SpringBean
我找到了以下解决方案,但不幸的是,我无法让它工作 我可以成功编译,但是当我测试应用程序时,我的Springbean总是空的 环境:在使用new关键字创建的对象中自动关联SpringBean,spring,maven,new-operator,autowired,aspectj-maven-plugin,Spring,Maven,New Operator,Autowired,Aspectj Maven Plugin,我找到了以下解决方案,但不幸的是,我无法让它工作 我可以成功编译,但是当我测试应用程序时,我的Springbean总是空的 环境: 雄猫7 JDK1.7/JRE7 编译器版本1.7 春季3.2.4 AspectJ 1.7.3 SpringAspects4.0.0 POM 月份: @Configuration @EnableWebMvc @EnableScheduling @EnableSpringConfigured @PropertySource("classpath:webappli
- 雄猫7
- JDK1.7/JRE7
- 编译器版本1.7
- 春季3.2.4
- AspectJ 1.7.3
- SpringAspects4.0.0
@Configuration
@EnableWebMvc
@EnableScheduling
@EnableSpringConfigured
@PropertySource("classpath:webapplication.properties")
@ComponentScan("com.root.package")
public class WebAppConfig extends WebMvcConfigurerAdapter {
...
}
public class Month {
private void fillDaysOfMonth() {
...
for (int i = 1; i <= date.getActualMaximum(Calendar.DAY_OF_MONTH); i++) {
Day day = new Day();
...
}
}
}
@Configurable
public class Day {
@Autowired private AbsenceService absenceService;
@Autowired private HolidayMasterdataService holidayMasterdataService;
}
你是否准备好了课堂上的设置器和获取器,以便自动连线工作?你需要为你计划注入的依赖项准备合适的设置器和获取器。不,它们没有。但是我添加了setter/getter和bean仍然没有被注入。这是@Configurable的一种特殊行为吗?因为如果我在类中自动连接相同的bean(由Spring初始化),我不需要setter/getter。另一个问题:我仍然需要maven编译器插件吗?你的应用程序中有很多手动创建的bean还是只有几个?
public class Month {
private void fillDaysOfMonth() {
...
for (int i = 1; i <= date.getActualMaximum(Calendar.DAY_OF_MONTH); i++) {
Day day = new Day();
...
}
}
}
@Configurable
public class Day {
@Autowired private AbsenceService absenceService;
@Autowired private HolidayMasterdataService holidayMasterdataService;
}