Chinaunix首页 | 论坛 | 博客
  • 博客访问: 125985
  • 博文数量: 39
  • 博客积分: 2565
  • 博客等级: 少校
  • 技术积分: 360
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-13 10:13
文章分类
文章存档

2013年(2)

2012年(2)

2011年(3)

2010年(3)

2009年(3)

2008年(10)

2007年(4)

2006年(12)

我的朋友

分类: 系统运维

2006-08-24 11:26:51

今天在写一个测试例子的时候,由于粗心+没有完全理解的问题导致在使用spring中的aop时出现了如下的问题:
严重: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'handlerMapping' defined in ServletContext resource [/WEB-INF/db-servlet.xml]: Cannot resolve reference to bean 'dbController' while setting bean property 'defaultHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbController' defined in ServletContext resource [/WEB-INF/db-servlet.xml]: Error setting property values; nested exception is PropertyAccessExceptionsException (1 errors)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbController' defined in ServletContext resource [/WEB-INF/db-servlet.xml]: Error setting property values; nested exception is PropertyAccessExceptionsException (1 errors)
Caused by: PropertyAccessExceptionsException (1 errors)
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0] to required type [com.testblob.DefaultDatabase] for property 'db'; nested exception is java.lang.IllegalArgumentException: No matching editors or conversion strategy found
Caused by: java.lang.IllegalArgumentException: No matching editors or conversion strategy found
 at org.springframework.beans.PropertyTypeConverter.convertIfNecessary(PropertyTypeConverter.java:209)
找了好久也没有找到错误原因,最后发现是在需要写接口的地方写成了实体类,很早以前就出现过同样的问题,当时解决了没有在意,今天又出现。所以写下来希望能帮助和我一样粗心的人解决问题。
 
 
java 源码:
ClobController.java文件内容
/**
 *
 */
package com.testblob;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import com.testblob.ClobDataBase;//
//import com.testblob.DefaultDatabase;//导致错误的源头,这是一个实体类
/**
 * @author ly
 *
 */
public class ClobController extends MultiActionController {
 private ClobDataBase db;
 //private DefaultDatabase db;//导致错误
 /**
  * @param db
  *            The db to set.
  */
 //public void setDb(DefaultDatabase db) {
 // this.db = db;
 //}导致错误
 public void setDb(ClobDataBase db) {
  this.db = db;
 }
 public ModelAndView showClobList(HttpServletRequest request, HttpServletResponse response) throws Exception {
  return new ModelAndView("clobList", "list", this.db.getContent());
 }
 public ModelAndView processStore(HttpServletRequest request, HttpServletResponse response) throws Exception {
  String name = request.getParameter("name");
  String content = request.getParameter("content");
  this.db.storeClob(name,content);
  return new ModelAndView("redirect:clobList.do");
 }
}
 
ClobDataBase.java文件内容
 
package com.testblob;
import java.io.OutputStream;
import java.util.List;
import org.springframework.dao.DataAccessException;
/**
 * @author ly
 *
 */
public interface ClobDataBase {
 List getContent() throws DataAccessException;
 void storeClob(String name, String content) throws DataAccessException;
}
 
DefaultDatabase.java文件内容

package com.testblob;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.jdbc.support.lob.LobCreator;
import org.springframework.jdbc.support.lob.LobHandler;
import org.springframework.jdbc.core.RowMapper;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatementCallback;
import org.springframework.jdbc.core.support.AbstractLobStreamingResultSetExtractor;
import org.springframework.jdbc.LobRetrievalFailureException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.util.FileCopyUtils;
/**
 * @author ly
 *
 */
public class DefaultDatabase extends JdbcDaoSupport implements ClobDataBase {
 private LobHandler lobHandler;

 /**
  * @param lobHandler The lobHandler to set.
  */
 public void setLobHandler(LobHandler lobHandler) {
  this.lobHandler = lobHandler;
 }

 /* (non-Javadoc)
  * @see com.testblob.ClobDataBase#getContent()
  */
 public List getContent() throws DataAccessException {
  // TODO Auto-generated method stub
  return getJdbcTemplate().query(
       "SELECT clob_content FROM clob_test",
       new RowMapper() {
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
         //String name = rs.getString(1);
         String description = lobHandler.getClobAsString(rs, 1);
         return description;
        }
       });
 }
 /* (non-Javadoc)
  * @see com.testblob.ClobDataBase#storeClob(java.lang.String, java.io.InputStream)
  */
 public void storeClob(final String name,final String content)
   throws DataAccessException {
  getJdbcTemplate().execute(
    "INSERT INTO clob_test (name, clob_content) VALUES (?, ?)",
    new AbstractLobCreatingPreparedStatementCallback(this.lobHandler) {
     protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
      ps.setString(1, name);
      lobCreator.setClobAsString(ps, 2, content);
     }
    }
  );

 }

}

applicationContext.xml配置文件内容


 
 
 
  
   
    WEB-INF/jdbc.properties
   

  

 
 
 
 
 
  
  
  
  
 
 
 
  
 
 
    lazy-init="true"/>
 
 
 
  
 

 
 
 
  
  
 
 
 
  
  
  
   
    PROPAGATION_REQUIRED,readOnly
    PROPAGATION_REQUIRED,readOnly
    PROPAGATION_REQUIRED
   

  

 
 
db-servlet.xml配置文件内容



 
 
 
  
  
 
 
 
 
  
 

 
 
 
  
   
    
     
      showClobList
      streamContent
      processStore
     

    

   

  

  
 
 
web.xml配置文件内容



 
  contextConfigLocation
  
   /WEB-INF/applicationContext.xml
  

 

 
  encodingFilter
  
   org.springframework.web.filter.CharacterEncodingFilter
  

  
   encoding
   GBK
  

  
   forceEncoding
   true
  

 

 
  encodingFilter
  *.do
 

 
  encodingFilter
  *.jsp
 

 
  
   org.springframework.web.context.ContextLoaderListener
  

 

 
  db
  
   org.springframework.web.servlet.DispatcherServlet
  

  2
 

 
  db
  *.do
 

 
  index.jsp
 




 
阅读(2381) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~