错误中学习--spring框架 org.springframework.beans.factory.NoSuchBeanDefinitionException

总结一下:org.springframework.beans.factory.NoSuchBeanDefinitionException:unique bean of type [en.db5q.model.Vdb5qList200301012001] is defined: Unsatified dependency of type [class en.db5q.model.Vdb5qList200301012001]


昨天的错误,同事说是没注解,于是了解了什么是注解式开发(Annotation),分别在实体类/action/serviceImpl/DaoImpl中添加了注解(详见收藏)

action
import java.lang.reflect.Type;
import java.util.List;

import javax.annotation.Resource;

import com.google.gson.Gson;
import com.htsoft.core.web.action.BaseAction;
import com.google.gson.reflect.TypeToken;

import en.db5q.service.DB5Q200301012001Service;
import en.db5q.model.Vdb5qList200301012001;

	@SuppressWarnings("serial")
	@Resource  //重点之处
public class DB5Q200301012001Action extends BaseAction {
	private DB5Q200301012001Service DB5Q200301012001Service;
		return DB5Q200301012001Service;
	private Vdb5qList200301012001 Vdb5qList200301012001;

	public DB5Q200301012001Service getDB5Q200301012001service() {
	}

		public Vdb5qList200301012001 getVdb5qList200301012001() {
	public void setDB5Q200301012001service(DB5Q200301012001Service dB5Q200301012001service) {
		DB5Q200301012001Service = dB5Q200301012001service;
	}

			return Vdb5qList200301012001;
		}

	        List<Vdb5qList200301012001> list= DB5Q200301012001Service.getAll();
		public void setVdb5qList200301012001(Vdb5qList200301012001 vdb5qList200301012001) {
			Vdb5qList200301012001 = vdb5qList200301012001;
		}
	/*显示功能*/
	 public String list(){
	        Type type=new TypeToken<List<Vdb5qList200301012001>>(){}.getType();
	        return SUCCESS;
	        StringBuffer buff = new StringBuffer("{success:true,'totalCounts':")
	        .append(list.size()).append(",result:");
			Gson gson = new Gson();	
	        buff.append(gson.toJson(list, type));
	        buff.append("}");
	        jsonString=buff.toString();
	    }
	 
}


serviceImpl
<span style="font-size:18px;">package en.db5q.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import en.db5q.dao.Vdb5qList200301012001Dao;
import en.db5q.model.Vdb5qList200301012001;
import en.db5q.service.DB5Q200301012001Service;
import be.sys.base.service.impl.StringBaseServiceImpl;
@Service  //重点之处
public class DB5Q200301012001ServiceImpl extends StringBaseServiceImpl<Vdb5qList200301012001> implements DB5Q200301012001Service{
<span style="color:#ff0000;">	@Resource</span>
	private Vdb5qList200301012001Dao dao;
    
	public DB5Q200301012001ServiceImpl(Vdb5qList200301012001Dao dao) {
		super(dao);
		this.dao = dao;
	}
}</span>
DaoImpl
<span style="font-size:18px;">package en.db5q.dao.impl;

import org.springframework.stereotype.Repository;

import be.sys.base.dao.impl.StringBaseDaoImpl;
import en.db5q.dao.Vdb5qList200301012001Dao;
import en.db5q.model.Vdb5qList200301012001;
@Repository  //重点之处
@SuppressWarnings("unchecked")
public class Vdb5qList200301012001DaoImpl extends StringBaseDaoImpl<Vdb5qList200301012001> implements Vdb5qList200301012001Dao{
	public Vdb5qList200301012001DaoImpl() {
		super(Vdb5qList200301012001.class);
	}
}</span>

然后重启tomcat 报错:could not open hibernate session for transaction,
查询后在 jdbc.properties 中给 jdbc.url 增加autoReconnect=true
即:#jdbc.url=jdbc:mysql://localhost/eoffice?useUnicode=true&amp;characterEncoding=utf-8&autoReconnect=true

然后重启 还是报错,于是又查找到spring配置文件app-resources.xml中发现一个红色错误 

改正方法:

因为local属性只有Spring 3.2这个版本有,所以特别指明http://www.springframework.org/schema/beans/spring-beans-3.2.xsd

然后还是报错,无奈之下对照别人的例子将注解重新写了一次,删掉了实体类的注解,最终注解如上面代码所示,然后重启tomcact终于得出了。


自我总结:由于不够了解ssh框架以及注解式开发,所以昨天出现了错误也无法解决。继续学习ssh框架,但是比较之前能够较顺畅地独自写下前后台(重点是后台,比较薄弱),实现了一个小功能。还学习了数据库建表,原谅我之前真没用过,还了解到断点怎么用。

看到几篇好博客,是我解决这次问题的灵感,po一下:
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值