Przerabiam kursy Pana Owczarka.
W połowie przerabiania tego filmiku wyrzuca mi błąd:
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'usersRepository' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:687)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1207)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1084)
at info.owczarek.springtutorial.Main.main(Main.java:14)
Main
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:konfiguracja.xml");
UsersRepository usersRepository = context.getBean("usersRepository", UsersRepository.class);
usersRepository.createUser("janek");
}
UsersRepositoryImpl
@Service("usersRepository")
public class UsersRepositoryImpl implements UsersRepository {
@Autowired
private Logger logger;
@Override
public User createUser(String name) {
logger.log("Tworzenie użytkownika " + name);
return new User(name);
}
@Override
public void setLogger(Logger logger) {
this.logger = logger;
}
}
konfiguracja
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<!-- <bean id="logger" class="info.owczarek.springtutorial.implementations.LoggerImpl"
/> <bean id="usersRepository" class="info.owczarek.springtutorial.implementations.UsersRepositoryImpl"
autowire="byType" /> -->
<context:annotation-config />
<context:component-scan base-package="info.owczarek.springutorial" />
</beans>
Struktura projektu
Proszę o pomoc / wskazówkę / poradę.