错误中学习--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 list= DB5Q200301012001Service.getAll();
		public void setVdb5qList200301012001(Vdb5qList200301012001 vdb5qList200301012001) {
			Vdb5qList200301012001 = vdb5qList200301012001;
		}
	/*显示功能*/
	 public String list(){
	        Type type=new TypeToken>(){}.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
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 implements DB5Q200301012001Service{
	@Resource
	private Vdb5qList200301012001Dao dao;
    
	public DB5Q200301012001ServiceImpl(Vdb5qList200301012001Dao dao) {
		super(dao);
		this.dao = dao;
	}
}
DaoImpl
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 implements Vdb5qList200301012001Dao{
	public Vdb5qList200301012001DaoImpl() {
		super(Vdb5qList200301012001.class);
	}
}

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

然后重启 还是报错,于是又查找到spring配置文件app-resources.xml中发现一个红色错误 
cvc-complex-type.3.2.2: Attribute 'key' is not allowed to appear in element 'props'

改正方法:
错误中学习--spring框架 org.springframework.beans.factory.NoSuchBeanDefinitionException_第1张图片
因为local属性只有Spring 3.2这个版本有,所以特别指明http://www.springframework.org/schema/beans/spring-beans-3.2.xsd

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


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

看到几篇好博客,是我解决这次问题的灵感,po一下:
点击打开链接
点击打开链接

你可能感兴趣的:(exception)