Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Spring could not autowire field, No matching bean of type
- SEVERE: Context initialization failed
- *.BeanCreationException: Error creating bean with name 'userServiceController': Injection of autowired dependencies failed;
- *.BeanCreationException: Error creating bean with name 'defaultUserService': Injection of autowired dependencies failed;
- *.BeanCreationException: Could not autowire field: private com.cloudlb.dao.UserDAO com.cloudlb.service.DefaultUserService.userDao;
- *.NoSuchBeanDefinitionException: No matching bean of type [com.cloudlb.dao.UserDAO]
- @Configuration
- @ComponentScan(basePackages = "com.cloudlb", excludeFilters = { @ComponentScan.Filter(Configuration.class)})
- public class ApplicationConfig {
- @Bean
- public static PropertyPlaceholderConfigurer properties() {
- final PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
- final Resource[] resources = new ClassPathResource[]{new ClassPathResource("persistence.properties"), new ClassPathResource("restful.properties")};
- ppc.setLocations(resources);
- ppc.setIgnoreUnresolvablePlaceholders(true);
- return ppc;
- }
- @Profile("hibernate")
- @EnableTransactionManagement
- public class PersistenceHibernateConfig { ...
- @Bean
- public LocalSessionFactoryBean alertsSessionFactoryBean() { ...
- @Bean
- public DataSource restDataSource() { ...
- @Bean
- public HibernateTransactionManager transactionManager() { ...
- @Configuration
- @EnableWebMvc
- public class WebConfig { ... }
- @Controller
- public class UserServiceController {
- @Autowired
- private UserService userService;
- @Service
- @Transactional(propagation = Propagation.REQUIRED)
- public class DefaultUserService implements UserService {
- @Autowired
- private UserDAO userDao;
- public interface UserDAO extends GenericDAO<User> { ... }
- @Profile("hibernate")
- public class UserHibernateDAO extends GenericHibernateDAO<User> implements UserDAO{ ... }
- @Profile("hibernate")
- @Scope(BeanDefinition.SCOPE_PROTOTYPE)
- public class GenericHibernateDAO<T extends Serializable> extends AbstractHibernateDAO<T> implements GenericDAO<T> { ... }
- @Transactional( propagation = Propagation.SUPPORTS )
- public abstract class AbstractHibernateDAO<T extends Serializable> implements DAO<T> {
- private Class<T> clazz;
- @Autowired
- private SessionFactory sessionFactory;
- public AbstractHibernateDAO() {
- super();
- }
- public final void setClazz(final Class<T> clazz) {
- this.clazz = clazz;
- }
- @Override
- @Transactional( readOnly = true )
- public T findById(String id) {
- return (T) this.getCurrentSession().get(this.clazz, id);
- }
- protected Session getCurrentSession() {
- return this.sessionFactory.getCurrentSession();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement