1. 程式人生 > >ssm增刪改查出現的問題總結

ssm增刪改查出現的問題總結

open 用戶名 int .org initial valid aps ltm neither

1.org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.mybatis.spring.mapper.MapperScannerConfigurer#0‘ defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [java.lang.String] to required type [org.apache.ibatis.session.SqlSessionFactory] for property ‘sqlSessionFactory‘; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.apache.ibatis.session.SqlSessionFactory] for property ‘sqlSessionFactory‘: no matching editors or conversion strategy found
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [java.lang.String] to required type [org.apache.ibatis.session.SqlSessionFactory] for property ‘sqlSessionFactory‘; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.apache.ibatis.session.SqlSessionFactory] for property ‘sqlSessionFactory‘: no matching editors or conversion strategy found
Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.apache.ibatis.session.SqlSessionFactory] for property ‘sqlSessionFactory‘: no matching editors or conversion strategy found
原因可能如下:1)@RequestMapping(value="/userlogin",method=RequestMethod.POST)
2)<!-- 配置映射接口 -->中property name="sqlSessionFactoryBeanName"

2.org.apache.ibatis.executor.ExecutorException:A query was run and no Result Maps were found for the Mapped Statement ‘com.blog.mapper.BlogMapper.findAllBlog‘. It‘s likely that neither a Result Type nor a Result Map was specified.
解決:仔細查看mybatis的配置文件,發現遺漏一個屬性:resultType
報錯的配置是:<select id="ID" parameterType="java.util.Map">
正確的配置應該是<select id="ID" parameterType="java.util.Map" resultType="java.util.Map">

最後總結下,就是mybatis中的所有查詢,都必須返回resultType或者resultMap的值,否則就會報如上錯誤的。

3.java.lang.NullPointerException
at com.blog.service.impl.BlogServiceImpl.findAllBlog(BlogServiceImpl.java:31)
at com.blog.controller.BlogController.findAllBlog(BlogController.java:27)
解決:空指針異常,可能是依賴關系沒有確定,看看屬性上是否添加@Autowired

4.java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
嚴重: Servlet.service() for servlet [springmvc] in context with path [/blog] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘username‘ not found. Available parameters are [arg1, arg0, param1, param2]] with root cause
org.apache.ibatis.binding.BindingException: Parameter ‘username‘ not found. Available parameters are [arg1, arg0, param1, param2]
解決: 查詢中參數沒有指定,比如://根據用戶名和密碼查詢 User find(String username,String password)應寫成//根據用戶名和密碼查詢
User find(@Param("username")String username,@Param("password")String password);

5.java.lang.NoSuchMethodException: com.opensymphony.xwork2.ActionSupport.login()

解決:applicationContext.xml中的依賴關系沒有註入

6.Caused by: java.lang.IllegalArgumentException: ‘sessionFactory‘ or ‘hibernateTemplate‘ is required
解決:applicationContext.xml中的依賴關系dao中沒有主人sessionFactory

7.Caused by: Action class [userAction] not found - action
解決:其實是缺少包struts2-sping-plugin 2.0.1.jar

8.使用c3p0數據源時,下邊的數據庫屬性分別是:driverClass,jdbcUrl,user,password
使用springjdbc數據源時,下邊的數據庫屬性分別是:driverClassName,url,username,password

ssm增刪改查出現的問題總結