Есть несколько классов объекты которых должны создаваться спрингом:
@Configuration
@ComponentScan
public class SpringConfig {
@Bean(name = "command")
@Scope("singleton")
CommandManagerImpl commandManager() {
return new CommandManagerImpl();
}
@Bean(name = "analyzer")
@Scope("singleton")
TasksAnalyzerImpl tasksAnalyzer() {
return new TasksAnalyzerImpl();
}
@Bean(name = "robot")
@Scope("singleton")
HumanizeRobot humanizeRobot() {
return new HumanizeRobot();
}
}
И сами классы
@Component
public class CommandManagerImpl implements CommandManager {
private Map<String, Command> commands;
@Autowired
private HumanizeRobot robot;
@Autowired
private TasksAnalyzer tasksAnalyzer;
private void initCommands() {
commands.put("task.list", new CommandImpl("task.list", robot, "update.task.list"));
}
//...
}
@Component
public class TasksAnalyzerImpl implements TasksAnalyzer {... тут внутри спринга нет}
@Component
public class HumanizeRobot {... тут внутри спринга нет}
Вызываю вот так:
ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
CommandManagerImpl commandManager = context.getBean(CommandManagerImpl.class);
Но падает с ошибкой в месте где есть попытка использовать объект HumanizeRobot который должен был создать спринг:
INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2d38eb89: startup date [Mon Dec 04 06:31:05 MSK 2017]; root of context hierarchy
Exception in thread "main" java.lang.NullPointerException
Не понимаю почему бины не создаются. Подскажите пожалуйста почему поля помеченные @Autowired не создаются спрингом? Спасибо.
@ComponentScan
Не указаны пакеты для сканирования.
Современные инструменты для криптотрейдинга: как технологии помогают принимать решения
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости