maven搭建ssm框架问题总结

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">应该驼峰命名,结果直接复制粘贴成小写了

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 196,099评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,473评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 143,229评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,570评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,427评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,335评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,737评论 3 386
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,392评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,693评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,730评论 2 312
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,512评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,349评论 3 314
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,750评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,017评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,290评论 1 251
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,706评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,904评论 2 335

推荐阅读更多精彩内容

  • 1. 简介 1.1 什么是 MyBatis ? MyBatis 是支持定制化 SQL、存储过程以及高级映射的优秀的...
    笨鸟慢飞阅读 5,403评论 0 4
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,517评论 18 139
  • 作者:邓姿 先生告诉我,他在吐鲁番有了亲 戚,一个叫艾木如拉的七岁小男孩,我 的脑海里立刻勾画出一个戴着闪闪发 光...
    忄and怡阅读 270评论 0 0
  • 妈蛋 肺都要吐出来了 总是折腾胃 活该 吐成这个样子。
    相相相柳阅读 174评论 0 0
  • 前几天超级碗中场秀让我狠狠的爽了一次,对就是这么直白,那种不到现场都燃的想哭的感觉,就像音符的能量转化成热量直冲我...
    Zuang阅读 410评论 0 3