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 → 对话框中的左侧选择Java → Installed JREs → 对话框右侧点击 Add 按钮 → Standard VM → next → JRE home 选择 JDK 的安装路径 → Finish → 选中 jdk 的复选框 → 点击 OK 按钮
按照《Maven实战》的内容,建议你不要使用 eclipse 内嵌的 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 因为前者不会调用tomcat7;
4.ssm整合时出现
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包,原来新版的驱动配置有些变化:
1. url连接必须设置时区
### 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
说明: 新版驱动url默认地址为127.0.0.1:3306,所以访问本机mysql数据库地址可以用 /// 表示。
2. 新的驱动类位置有了变化(不影响使用,但会报警告)
### MySQL Connector/J 5.x (旧版驱动)
#jdbc.driver_class=com.mysql.jdbc.Driver
### MySQL Connector/J 6.x (新版驱动)
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数据库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逆向工程时,重复使用了两次,结果在对应的映射文件中重复生成了两份内容,所有 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包发生冲突。当程序运行时与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逆向工程时,重复使用了两次,结果在对应的映射文件中重复生成了两份内容,所有 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包发生冲突。当程序运行时与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的配置文件,发现遗漏一个属性:resultType
报错的配置是:
正确的配置应该是
最后总结下,就是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)
解决:空指针异常,可能是依赖关系没有确定,看看属性上是否添加@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]
解决: 查询中参数没有指定,比如://根据用户名和密码查询 User find(String username,String password)应写成//根据用户名和密码查询
User find(@Param("username")String username,@Param("password")String password);
20.java.lang.NoSuchMethodException: com.opensymphony.xwork2.ActionSupport.login()
解决:applicationContext.xml中的依赖关系没有注入
21.Caused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
解决:applicationContext.xml中的依赖关系dao中没有主人sessionFactory
22.Caused by: Action class [userAction] not found - action
解决:其实是缺少包struts2-sping-plugin 2.0.1.jar
23.使用c3p0数据源时,下边的数据库属性分别是:driverClass,jdbcUrl,user,password
使用springjdbc数据源时,下边的数据库属性分别是: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">应该驼峰命名,结果直接复制粘贴成小写了
网友评论