Я получаю следующее исключение:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.servlet.http.HttpServletRequest] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 56 more
Полная трассировка стека здесь
А вот мой JUnit:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = TestConfig.class)
@Transactional
public class Prueba {
private static final String FIRSTNAME = "TestFirstName";
private static final String LASTNAME = "TestLastName";
private static final String EMAIL = "test@mail.com";
private static final String PASSWORD = "TestPassword";
private static final String PHONENUMBER = "00000000";
private static final String ROLE = "USER";
@PersistenceContext
private EntityManager em;
@Autowired
private UserHibernateDao userDao; // THIS SEEMS TO BE THE ISSUE!
private JdbcTemplate jdbcTemplate;
private long user_id;
@Before
@Transactional
public void setUp() {
User u;
for (int i = 0; i < 50; i++) {
u = new User();
u.setFirstName(i + FIRSTNAME + i);
u.setLastName(i + LASTNAME + i);
u.setEmail(i + EMAIL);
u.setLocked(false);
em.persist(u);
if (i == 10) {
this.user_id = u.getUserid();
}
}
}
@Rollback
@Test
public void testCreate() {
final User user = userDao.create(FIRSTNAME, LASTNAME, EMAIL, PASSWORD, PHONENUMBER, ROLE);
assertNotNull(user);
}
}
проблема, как я указал в коде, кажется, когда я автоматически подключаю UserHibernateDao.
Вот мой TestConfig:
@ComponentScan({"src.main.java.ar.edu.itba.paw.persistence", })
@Configuration
public class TestConfig {
@Bean
public DataSource dataSource() {
final SimpleDriverDataSource ds = new SimpleDriverDataSource();
ds.setDriverClass(JDBCDriver.class);
ds.setUrl("jdbc:hsqldb:mem:paw");
ds.setUsername("ha");
ds.setPassword("");
return ds;
}
@Bean
public LocalContainerEntityManagerFactoryBean getEntityManagerFactory() {
final LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setPackagesToScan("ar.edu.itba.paw.models");
factoryBean.setDataSource(dataSource());
final JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
factoryBean.setJpaVendorAdapter(vendorAdapter);
final Properties properties = new Properties();
properties.setProperty("hibernate.hbm2ddl.auto", "update");
properties.setProperty("hibernate.search.default.directory_provider", "filesystem");
properties.setProperty("hibernate.search.default.indexBase", "lucene/indexes");
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
properties.setProperty("hibernate.show_sql", "true");
properties.setProperty("format_sql", "true");
factoryBean.setJpaProperties(properties);
return factoryBean;
}
@Bean
public PlatformTransactionManager transactionManager(final EntityManagerFactory emf) {
return new JpaTransactionManager(emf);
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
А вот как выглядят мои пакеты:
Любые идеи по как это исправить?
Я попытался изменить свой @ComponentScan ({"sr c .main. java .ar.edu.itba.paw.persistence",})
to @ComponentScan ({"ar.edu.itba.paw.persistence",})
Но это тоже не работает.
Также вот мой UserHibernateDao класс .