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é)果直接復制粘貼成小寫了