Spring报错:expected at least 1 matching bean还是没解决

问题描述

严重: 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呀

时间: 2024-09-18 00:57:55

Spring报错:expected at least 1 matching bean还是没解决的相关文章

代码-spring报错 mismatched input &amp;amp;#39;gt&amp;amp;#39; expecting EOF

问题描述 spring报错 mismatched input 'gt' expecting EOF 代码如下: <?xml version="1.0" encoding="UTF-8"?> xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util

python-Python使用正则表达式报错expected string or buffer

问题描述 Python使用正则表达式报错expected string or buffer [求大神们帮帮忙啊,用正则表达式删除文本的特定片段报错,把search那里用str强制转换也不行] 解决方案 myfile是_io.TextIOWrapper类型,re.search()并不支持这个类型,也不支持list. 倒是可以用re.search('...', myfile.read()),或者可以遍历myfile的每一行: for line in myfile: re.search('...',

spring 报错,求高手解答

问题描述 spring 报错,求高手解答 代码: package com.test.aop; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annota

Spring 报错:元素 &quot;context:component-scan&quot; 的前缀 &quot;context&quot; 未绑定的问题解决_java

Spring 配置文件报错:元素 "context:component-scan" 的前缀 "context" 未绑定,这是我在做项目的时候遇到的,经过项目经理及同事提醒解决了,这里就说下如何解决.      1.spring配置信息如下 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.o

android studio 报错,请问这是怎么回事?怎么解决

问题描述 android studio 报错,请问这是怎么回事?怎么解决 Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(com.qihoo.sdk.report.b) that doesn't come with an Error:associated EnclosingMethod attribute. This class was probably produced by

c#项目,用的是vs2012打开的,报错没有工具集,求大神帮忙解决一下,谢谢了!!拜托拜托!

问题描述 c#项目,用的是vs2012打开的,报错没有工具集,求大神帮忙解决一下,谢谢了!!拜托拜托! 项目文件包含 ToolsVersion="12.0".此工具集可能未知或缺失(您可以通过安装相应版本的 MSBuild 来解决该问题),或者该生成因策略原因已被强制更改为特殊 ToolsVersion.将此项目视作具有 ToolsVersion="4.0".有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkId=2913

junit-dbunit-2.4.8+poi-3.2-final测试报错,各位大神有知道的没,求指导

问题描述 dbunit-2.4.8+poi-3.2-final测试报错,各位大神有知道的没,求指导 java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFRow.getCell(I)Lorg/apache/poi/hssf/usermodel/HSSFCell; at org.dbunit.dataset.excel.XlsTable.createMetaData(XlsTable.java:91) at org.dbuni

Android Studio 报错failed to create jvm error code -4的解决方法_Android

安装完 Android Studio 后启动,却报错如下: 复制代码 代码如下: failed to create jvm error code -4 这一般应是内存不够用所致,解决方法参考如下. 打开 Android Studio 安装目录下的bin目录,查找并打开文件 studio.exe.vmoptions,修改代码: 复制代码 代码如下: -Xmx512m 为 -Xmx256m 保存后应即可正常打开了.

Apache启动报错No space left on device: AH00023该怎么解决_php实例

Apache启动报错No space left on device: AH00023错误可能是进程导致了,虽然小编不知道什么原因但网上提供的解决办法确实是可以解决我们的问题,下面来看看. 对于这类错误是因为linux系统的ipc信号量造成的,apache启动时,会创建很多子进程.他们是通过信号量来和子进程进行通信的. 信号量介绍: 信号量又称为信号灯,它是用来协调不同进程间的数据对象的,而最主要的应用是共享内存方式的进程间通信.本质上,信号量是一个计数器,它用来记录对某个资源(如共享内存)的存取