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 → 對(duì)話框中的左側(cè)選擇Java → Installed JREs → 對(duì)話框右側(cè)點(diǎn)擊 Add 按鈕 → Standard VM → next → JRE home 選擇 JDK 的安裝路徑 → Finish → 選中 jdk 的復(fù)選框 → 點(diǎn)擊 OK 按鈕
按照《Maven實(shí)戰(zhàn)》的內(nèi)容努溃,建議你不要使用 eclipse 內(nèi)嵌的 Maven。而是給 eclipse 配置電腦上安裝的 Maven。這樣保證版本一致彪标,可以避免一些問題堕扶。
2.Caused by: java.net.BindException: Address already in use: JVM_Bind :8080
解決:端口被占用扁耐,可能運(yùn)行兩次tomcat
3.嚴(yán)重: Compilation error org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException:
嚴(yán)重: 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
解決:項(xiàng)目正常啟動(dòng),但是無法在瀏覽器中打開,報(bào)的錯(cuò)是 org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException用踩,是tomcat:run的問題
在web項(xiàng)目的pom文件中增加tomcat7配置
org.apache.tomcat.maven
tomcat7-maven-plugin
2.2
9999
UTF-8
啟動(dòng)tomcat插件,不過這次的命令不是tomcat:run 而是tomcat7:run 因?yàn)榍罢卟粫?huì)調(diào)用tomcat7;
4.ssm整合時(shí)出現(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時(shí)使用的是MySQL最新jar包忙迁,原來新版的驅(qū)動(dòng)配置有些變化:
1. url連接必須設(shè)置時(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ū)動(dòng)url默認(rèn)地址為127.0.0.1:3306脐彩,所以訪問本機(jī)mysql數(shù)據(jù)庫(kù)地址可以用 /// 表示。
2. 新的驅(qū)動(dòng)類位置有了變化(不影響使用姊扔,但會(huì)報(bào)警告)
### MySQL Connector/J 5.x (舊版驅(qū)動(dòng))
#jdbc.driver_class=com.mysql.jdbc.Driver
### MySQL Connector/J 6.x (新版驅(qū)動(dòng))
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'
解決:是因?yàn)樵趗ser實(shí)體類中封裝dept屬性時(shí)惠奸,在mapper.xml中的增加insert數(shù)據(jù)庫(kù)sql中寫的是did,應(yīng)該寫成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
路徑錯(cuò)誤恰梢,找不到mysqljar包佛南,更改路徑即可
8.錯(cuò)誤: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逆向工程時(shí),重復(fù)使用了兩次嵌言,結(jié)果在對(duì)應(yīng)的映射文件中重復(fù)生成了兩份內(nèi)容嗅回,所有 Result Maps collection already contains value錯(cuò)誤
9.問題:Caused by: java.lang.ClassCastException: org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer
解決:原因:在我的pom.xml文件中javax.servlet-api.jar包發(fā)生沖突。當(dāng)程序運(yùn)行時(shí)與tomcat中的jar包沖突了摧茴,只需要它在測(cè)試绵载、編譯階段有用
可以限制作用范圍
10.問題:Caused by: org.apache.catalina.LifecycleException: A child container failed during start
在pom.xml引入的servlet-api依賴時(shí),需要加入provided這個(gè)配置苛白,意思是這個(gè)servlet-api的依賴包只在編譯和測(cè)試時(shí)使用而不在運(yùn)行時(shí)使用
11.Caused by: java.lang.UnsupportedOperationException
解決:原因是我的namespace中的select返回類型 resultType是List,應(yīng)該是resultType返回的是集合中的元素類型娃豹,而不是集合本身
12.插入的時(shí)候,userMapper.xml如果使用的是values(#{id},#{name},#{age},#{sex}),不能加雙引號(hào)购裙。
如果使用的是values(${id},"${name}","${age}","${sex}")懂版,需要加雙引號(hào)
13.錯(cuò)誤: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逆向工程時(shí),重復(fù)使用了兩次躏率,結(jié)果在對(duì)應(yīng)的映射文件中重復(fù)生成了兩份內(nèi)容躯畴,所有 Result Maps collection already contains value錯(cuò)誤
14.問題:Caused by: java.lang.ClassCastException: org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer
解決:原因:在我的pom.xml文件中javax.servlet-api.jar包發(fā)生沖突民鼓。當(dāng)程序運(yùn)行時(shí)與tomcat中的jar包沖突了,只需要它在測(cè)試私股、編譯階段有用
可以限制作用范圍
15.問題:java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException
解決:必須引入logback-classic-0.9.24.jar/logback-core-0.9.24.jar這兩個(gè)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.
解決:仔細(xì)查看mybatis的配置文件,發(fā)現(xiàn)遺漏一個(gè)屬性:resultType
報(bào)錯(cuò)的配置是:
正確的配置應(yīng)該是
最后總結(jié)下倡鲸,就是mybatis中的所有查詢,都必須返回resultType或者resultMap的值黄娘,否則就會(huì)報(bào)如上錯(cuò)誤的峭状。
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
嚴(yán)重: 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)應(yīng)寫成//根據(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?
解決:其實(shí)是缺少包struts2-sping-plugin 2.0.1.jar
23.使用c3p0數(shù)據(jù)源時(shí),下邊的數(shù)據(jù)庫(kù)屬性分別是:driverClass誓焦,jdbcUrl胆敞,user,password
使用springjdbc數(shù)據(jù)源時(shí)杂伟,下邊的數(shù)據(jù)庫(kù)屬性分別是: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">應(yīng)該駝峰命名观话,結(jié)果直接復(fù)制粘貼成小寫了