maven搭建ssm框架問題總結(jié)

1.Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.0:compile (default-compile) on project jcseg-core: Compilation failure

[ No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

解決:把 JRE 路徑從 JRE 改成 JDK:

Window → Preferences → 對話框中的左側(cè)選擇Java → Installed JREs → 對話框右側(cè)點擊 Add 按鈕 → Standard VM → next → JRE home 選擇 JDK 的安裝路徑 → Finish → 選中 jdk 的復選框 → 點擊 OK 按鈕

按照《Maven實戰(zhàn)》的內(nèi)容,建議你不要使用 eclipse 內(nèi)嵌的 Maven。而是給 eclipse 配置電腦上安裝的 Maven。這樣保證版本一致,可以避免一些問題。

2.Caused by: java.net.BindException: Address already in use: JVM_Bind :8080

解決:端口被占用,可能運行兩次tomcat

3.嚴重: Compilation error org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException:

嚴重: Servlet.service() for servlet jsp threw exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 1 in the generated java file

The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files

解決:項目正常啟動,但是無法在瀏覽器中打開,報的錯是 org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException,是tomcat:run的問題

在web項目的pom文件中增加tomcat7配置

org.apache.tomcat.maven

tomcat7-maven-plugin

2.2

9999

UTF-8

啟動tomcat插件,不過這次的命令不是tomcat:run 而是tomcat7:run 因為前者不會調(diào)用tomcat7;

4.ssm整合時出現(xiàn)

java.sql.SQLException: The server time zone value '?й???????' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value '?й???????' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

解決:配置pom.xml時使用的是MySQL最新jar包,原來新版的驅(qū)動配置有些變化:


1. url連接必須設(shè)置時區(qū)

### MySQL Connector/J 5.x (舊版連接)

#jdbc.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8

### MySQL Connector/J 6.x (新版連接)

jdbc.url=jdbc:mysql:///test?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false

說明: 新版驅(qū)動url默認地址為127.0.0.1:3306,所以訪問本機mysql數(shù)據(jù)庫地址可以用 /// 表示。


2. 新的驅(qū)動類位置有了變化(不影響使用,但會報警告)

### MySQL Connector/J 5.x (舊版驅(qū)動)

#jdbc.driver_class=com.mysql.jdbc.Driver

### MySQL Connector/J 6.x (新版驅(qū)動)

jdbc.driver_class=com.mysql.cj.jdbc.Driver


5.org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'did' in 'class com.ssm.entity.User'

解決:是因為在user實體類中封裝dept屬性時,在mapper.xml中的增加insert數(shù)據(jù)庫sql中寫的是did,應該寫成dept.did


6.Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.taobao.mapper.ProductMapper com.taobao.service.ProductServiceImpl.productMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.taobao.mapper.ProductMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

解決:applicationContex.xml中沒有正確配置MapperScannerConfigurer


7.[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate (default-cli) on project mmall_learning: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate failed: Cannot resolve classpath entry: /Users/yujie/Workspaces/IdeaProjects/mmall_learing/lib/mysql-connector-java-5.1.6-bin.jar -> [Help 1]

解決:原因是datasource.properties中的db.driverLocation=/Users/Administrator/workspace/yhMall/tools/mysql-connector-java-5.1.6-bin.jar

路徑錯誤,找不到mysqljar包,更改路徑即可


8.錯誤:Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.mmall.dao.OrderMapper.BaseResultMap

Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.mmall.dao.OrderMapper.BaseResultMap

解決:原因是我在使用mybatis逆向工程時,重復使用了兩次,結(jié)果在對應的映射文件中重復生成了兩份內(nèi)容,所有 Result Maps collection already contains value錯誤


9.問題:Caused by: java.lang.ClassCastException: org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer

解決:原因:在我的pom.xml文件中javax.servlet-api.jar包發(fā)生沖突。當程序運行時與tomcat中的jar包沖突了,只需要它在測試、編譯階段有用

可以限制作用范圍

10.問題:Caused by: org.apache.catalina.LifecycleException: A child container failed during start

在pom.xml引入的servlet-api依賴時,需要加入provided這個配置,意思是這個servlet-api的依賴包只在編譯和測試時使用而不在運行時使用

11.Caused by: java.lang.UnsupportedOperationException

解決:原因是我的namespace中的select返回類型 resultType是List,應該是resultType返回的是集合中的元素類型,而不是集合本身

12.插入的時候,userMapper.xml如果使用的是values(#{id},#{name},#{age},#{sex}),不能加雙引號。

如果使用的是values(${id},"${name}","${age}","${sex}"),需要加雙引號

13.錯誤:Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.mmall.dao.OrderMapper.BaseResultMap

Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.mmall.dao.OrderMapper.BaseResultMap

解決:原因是我在使用mybatis逆向工程時,重復使用了兩次,結(jié)果在對應的映射文件中重復生成了兩份內(nèi)容,所有 Result Maps collection already contains value錯誤

14.問題:Caused by: java.lang.ClassCastException: org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer

解決:原因:在我的pom.xml文件中javax.servlet-api.jar包發(fā)生沖突。當程序運行時與tomcat中的jar包沖突了,只需要它在測試、編譯階段有用

可以限制作用范圍

15.問題:java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException

解決:必須引入logback-classic-0.9.24.jar/logback-core-0.9.24.jar這兩個jar包,切版本要一致

16.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"

17..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的配置文件,發(fā)現(xiàn)遺漏一個屬性:resultType

報錯的配置是:

正確的配置應該是

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

18.java.lang.NullPointerException

at com.blog.service.impl.BlogServiceImpl.findAllBlog(BlogServiceImpl.java:31)

at com.blog.controller.BlogController.findAllBlog(BlogController.java:27)

解決:空指針異常,可能是依賴關(guān)系沒有確定,看看屬性上是否添加@Autowired

19.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]

解決: 查詢中參數(shù)沒有指定,比如://根據(jù)用戶名和密碼查詢 User find(String username,String password)應寫成//根據(jù)用戶名和密碼查詢

User find(@Param("username")String username,@Param("password")String password);

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

解決:applicationContext.xml中的依賴關(guān)系沒有注入

21.Caused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required

解決:applicationContext.xml中的依賴關(guān)系dao中沒有主人sessionFactory

22.Caused by: Action class [userAction] not found - action?

解決:其實是缺少包struts2-sping-plugin 2.0.1.jar

23.使用c3p0數(shù)據(jù)源時,下邊的數(shù)據(jù)庫屬性分別是:driverClass,jdbcUrl,user,password

使用springjdbc數(shù)據(jù)源時,下邊的數(shù)據(jù)庫屬性分別是:driverClassName,url,username,password

24.Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [org.mybatis.spring.transaction.SpringManagedTransactionFactory]: Bean property 'dataSource' is not writable or has an invalid setter method. Do

原因:<property name="dataSource">應該駝峰命名,結(jié)果直接復制粘貼成小寫了

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

  • 1. 簡介 1.1 什么是 MyBatis ? MyBatis 是支持定制化 SQL、存儲過程以及高級映射的優(yōu)秀的...
    笨鳥慢飛閱讀 6,241評論 0 4
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,568評論 19 139
  • 作者:鄧姿 先生告訴我,他在吐魯番有了親 戚,一個叫艾木如拉的七歲小男孩,我 的腦海里立刻勾畫出一個戴著閃閃發(fā) 光...
    忄and怡閱讀 336評論 0 0
  • 媽蛋 肺都要吐出來了 總是折騰胃 活該 吐成這個樣子。
    相相相柳閱讀 197評論 0 0
  • 前幾天超級碗中場秀讓我狠狠的爽了一次,對就是這么直白,那種不到現(xiàn)場都燃的想哭的感覺,就像音符的能量轉(zhuǎn)化成熱量直沖我...
    Zuang閱讀 488評論 0 3

友情鏈接更多精彩內(nèi)容