问题描述
严重: Exception sending context initialized event to listener instance of class cn.tg.core.web.ApplicationListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'systemConfigMngImpl': Autowiring of methods failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void cn.tg.core.manager.impl.SystemConfigMngImpl.setDao(cn.tg.core.dao.SystemConfigDao); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [cn.tg.core.dao.SystemConfigDao] is defined: Unsatisfied dependency of type [interface cn.tg.core.dao.SystemConfigDao]: expected at least 1 matching bean 实体类 SystemConfig Java代码 @Entity @Table(name = "tg_system") public class SystemConfig implements Serializable { private static final long serialVersionUID = 2776461377886734127L; private long id; @Id @GeneratedValue(strategy = GenerationType.AUTO) public long getId() { return id; } …… @Entity@Table(name = "tg_system")public class SystemConfig implements Serializable {private static final long serialVersionUID = 2776461377886734127L;private long id; @Id@GeneratedValue(strategy = GenerationType.AUTO)public long getId() {return id;}……Mng接口 Java代码 1.public interface SystemConfigMng extends TGCoreManager<SystemConfig>{ 2.} public interface SystemConfigMng extends TGCoreManager<SystemConfig>{}Mng实现类 @Service // systemConfigMngImpl @Transactional public class SystemConfigMngImpl extends TGCoreManagerImpl<SystemConfig> implements SystemConfigMng { @Autowired public void setDao(SystemConfigDao dao) { super.setDao(dao); } public SystemConfigDao getDao() { return (SystemConfigDao) super.getDao(); } } 在一个servelt里: Java代码 1.public final class ApplicationListener implements ServletContextListener { 2. private static final String BEAN_NAME = "systemConfigMngImpl"; 3. private static final Logger log = LoggerFactory 4. .getLogger(ApplicationListener.class); 5. 6. public void contextDestroyed(ServletContextEvent event) { 7. } 8. 9. public void contextInitialized(ServletContextEvent event) { 10. WebApplicationContext wac = WebApplicationContextUtils 11. .getRequiredWebApplicationContext(event.getServletContext()); 12. systemConfigMng = (SystemConfigMng) wac.getBean(BEAN_NAME, SystemConfigMng.class); 13. log.info("系统启动,读取所有站点信息到缓存。"); 14. systemConfigMng.loadAllSystemConfigToCache(); 15. } 16. 17. private SystemConfigMng systemConfigMng; 18.} public final class ApplicationListener implements ServletContextListener {private static final String BEAN_NAME = "systemConfigMngImpl";private static final Logger log = LoggerFactory.getLogger(ApplicationListener.class);public void contextDestroyed(ServletContextEvent event) {}public void contextInitialized(ServletContextEvent event) {WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext());systemConfigMng = (SystemConfigMng) wac.getBean(BEAN_NAME, SystemConfigMng.class);log.info("系统启动,读取所有站点信息到缓存。");systemConfigMng.loadAllSystemConfigToCache();}private SystemConfigMng systemConfigMng;}用了systemConfigMngImpl就报上面的错,那位大侠能帮忙解决吗?现在那个热锅上的蚂蚁啊!!只有那么多分了……万分感谢!!! Java代码 1.public interface BaseDao<T extends Serializable> {…//底层dao接口…} 2. 3.@Repository 4.public abstract class BaseDaoImpl<T extends Serializable> implements BaseDao<T> { 5. protected Logger log = LoggerFactory.getLogger(getClass()); 6. 7. protected SessionFactory sessionFactory; 8. 9. @Autowired 10. public void setSessionFactory(SessionFactory sessionFactory) { 11. this.sessionFactory = sessionFactory; 12. } 13.…//底层dao实现类… 14.} 15.public interface BaseManager<T extends Serializable> {//底层 16.Mng接口} 17. 18.@Transactional 19.public class BaseManagerImpl<T extends Serializable> implements BaseManager<T> { 20. protected Logger log = LoggerFactory.getLogger(getClass()); 21. private BaseDao<T> dao; 22. 23. public void setDao(BaseDao<T> dao) { 24. this.dao = dao; 25. } 26. 27. protected BaseDao<T> getDao() { 28. return this.dao; 29. } 30.//底层Mng实现类 31.} 32. 33.public interface TGCoreDao<T extends Serializable> extends BaseDao<T> { 34. 35.} 36. 37.public class TGCoreDaoImpl<T extends Serializable> extends BaseDaoImpl<T> 38. implements TGCoreDao<T> { 39. 40. 41.} 42. 43.public interface TGCoreManager<T extends Serializable> extends BaseManager<T> { 44.} 45. 46.public class TGCoreManagerImpl<T extends Serializable> extends 47. BaseManagerImpl<T> implements TGCoreManager<T> { 48.} public interface BaseDao<T extends Serializable> {…//底层dao接口…}@Repositorypublic abstract class BaseDaoImpl<T extends Serializable> implements BaseDao<T> {protected Logger log = LoggerFactory.getLogger(getClass());protected SessionFactory sessionFactory;@Autowiredpublic void setSessionFactory(SessionFactory sessionFactory) {this.sessionFactory = sessionFactory;}…//底层dao实现类…}public interface BaseManager<T extends Serializable> {//底层Mng接口}@Transactionalpublic class BaseManagerImpl<T extends Serializable> implements BaseManager<T> {protected Logger log = LoggerFactory.getLogger(getClass());private BaseDao<T> dao;public void setDao(BaseDao<T> dao) {this.dao = dao;}protected BaseDao<T> getDao() {return this.dao;}//底层Mng实现类}public interface TGCoreDao<T extends Serializable> extends BaseDao<T> {}public class TGCoreDaoImpl<T extends Serializable> extends BaseDaoImpl<T>implements TGCoreDao<T> {}public interface TGCoreManager<T extends Serializable> extends BaseManager<T> {}public class TGCoreManagerImpl<T extends Serializable> extendsBaseManagerImpl<T> implements TGCoreManager<T> {}Dao接口 Java代码 1.public interface SystemConfigDao extends TGCoreDao<SystemConfig> { 2. 3.} public interface SystemConfigDao extends TGCoreDao<SystemConfig> {}Dao实现类 Java代码 1.public class SystemConfigDaoImpl extends TGCoreDaoImpl<SystemConfig> implements SystemConfigDao{ 2. 3.}
解决方案
public class SystemConfigDaoImpl 上加上@Repository
解决方案二:
config文件咩有定义相对应的bean还有你的bean需要加上@Service或者Repository
解决方案三:
说你的systemConfigMngImpl里面的dao没有定义相应的bean。
解决方案四:
public class SystemConfigMngImpl extends TGCoreManagerImpl<SystemConfig> implements SystemConfigMng { @Autowired public void setDao(SystemConfigDao dao) { super.setDao(dao); } public SystemConfigDao getDao() { return (SystemConfigDao) super.getDao(); } } 这是你的代码吧,里面应该写注入的对象吧private SystemConfigDao dao;这一行之后才能get,set呀