spring 报错
一. java.lang.ClassNotFoundException: org.springframework.web.filter.CharacterEncodingFilter
解决方案:
1.看WEB-INF下面有没有lib,没有就自己创建一个
2.右键改工程,选择properties
3.再选择Deployment Assembly
4.点击add
5.选择Java Build Path Entries后点击next
6.选择Maven Dependencies后点击finish
7.点击Apply后点击OK
重启tomcat就可以了
二. Caused by: java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver]
原因: Libraires 里没有相关mysql-connector-java的jar包
解决方法: 在pom.xml 加入以下依赖项即可
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.</version>
</dependency>
三. java.lang.ClassNotFoundException: org.mybatis.spring.SqlSessionFactoryBean
原因: Libraires 里没有org.mybatis的jar包
解决方法: 在pom.xml 加入以下依赖项即可
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.</version>
</dependency>
四.mybatis报错:The alias 'xxx' is already mapped to the value 'com.demo.xxx'
经过分析,原来是因为配置文件中,mybatis指定别名时,指定的是一个包路径,而不是一个具体的类。恰巧该项目依赖的jar包中,有2个不同jar包,存在同名类,并且所在包路径的顶层是相同的,故而出现此错误。


修改方法很简单,可以修改配置文件中的包路径,或者修改其中一个类名。
五. 报警不能发现 InternalResourceViewResolver 类
原因: springmvc-config.xml 漏加 beanclass="controller.ProductController" /> //controller.ProductController 是自己编写的控制器
加好后配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan
base-package="app18b.controller" />
<mvc:annotation-driven />
<mvc:resources mapping="/css/ **" location="/css/" />
<mvc:resources mapping="/ *.html" location="/" />
<!-- Register the bean -->
<bean class="controller.ProductController" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" /> </bean>
</beans>
六. 报警 Ambiguous mapping. Cannot map 'controller.ProductController#0' method
原因 springmvc-config文件定义了一个ProductController,使用@service注解时又自动创建了一个ProductController
错误springmvc-config配置
<context:component-scan base-package="controller"/>
<context:component-scan base-package="service"/>
<mvc:annotation-driven/>
<mvc:resources mapping="/css/ **" location="/css/"/>
<mvc:resources mapping="/ *.html" location="/"/>
<!-- Register the bean -->
<bean class="controller.ProductController" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean> </beans>
修改后springmvc-config配置
<context:component-scan base-package="controller"/>
<context:component-scan base-package="service"/>
<mvc:annotation-driven/>
<mvc:resources mapping="/css/ **" location="/css/"/>
<mvc:resources mapping="/ *.html" location="/"/>
<!-- Register the bean -->
<!-- <bean class="controller.ProductController" /> -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean> </beans>
七 报错没有bean没有init()方法 .java.lang.NoSuchMethodException: domain.Category.<init>()
原因: java bean 设置了有参构造函数,导致bean 不能初始化
解决方法: 去掉构造函数的参数,或者加上一个无参构造函数
八 不能为属性:[commandName]找到setter 方法.
<div id="global">
<form:form commandName="book" action="/book_update" method="post">
<fieldset>
<legend>Edit a book</legend>
<form:hidden path="id" />
原因: commandName 已被淘汰
解决方法: 改用 modelAttribute 即可
九 :Spring url 格式转换错误:
警告: Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'long'; nested exception is java.lang.NumberFormatException: For input string: "book_update"]
原因: 表单form的action错误
错误的url

错误的表单
<form:form modelAttribute="book" action="book_update" method="post">
解决方法
修改action加上项目名
<form:form modelAttribute="book" action="/app19a/book_update" method="post">
正确的url
http://localhost:8080/app19a/book_list
spring 报错的更多相关文章
- spring报错NoClassDefFoundError等与第三方jar包导入问题
今天配置spring,遇到各种报错的问题,做一个小小总结. 1.刚开始我忘了引入commons-logging,报错.--解决方式:下载并引入该jar包 2.spring以及commons-loggi ...
- Spring报错:Exception in thread "main" java.lang.IllegalArgumentException at org.springframework.asm.ClassReader.<init>(Unknown Source)
简单搭建了一个Spring Maven工程就报错: 看到网上说是JDK 7 和 Spring3.x :JDK编译级别设置成1.7,仍然没有得到解决,采用版本为 3.2.0.RELEASE <b ...
- Spring报错: org.springframework.beans.factory.support.BeanDefinitionValidationException: Couldn't find an init method named 'init' on bean with name 'car'(待解答)
在Spring工程里,有一个Car类的bean,Main.java主程序,MyBeanPostProcessor.java是Bean后置处理器. 文件目录结构如下: Car.java package ...
- Spring报错:java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
感谢:http://blog.chinaunix.net/uid-20681545-id-184633.html提供的解决方案,非常棒 ! 问题说明: 新建一个Spring项目,新建一个Bean类:H ...
- 安装spring报错:Cannot complete the install because of a conflicting dependency.
问题: 在Eclipse里安装Spring插件,help->install new software用端点安装,说是出现软件依赖错误报错如下: Cannot complete the insta ...
- Spring报错汇总笔记
报错信息: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing X ...
- spring报错can't find resources
整合spring的时候报错can't find resource[../././.xml] 这两天在整个spring,发现单元测试的时候就可以正常运行,放在tomcat中就报错initial cont ...
- Spring报错——Scope 'session' is not active for the current thread
在对程序进行了一些修改后,运行发现spring报了这个错误,这是由于我设置了一个@Scope("session")导致的,现记录下解决方法. 解决方法: 将Scope设置为scop ...
- 无法解析db.properties,spring报错:Caused by: java.sql.SQLException: unkow jdbc driver : ${url}
db.properties中配置了url等jdbc连接属性: driver=org.sqlite.JDBCurl=jdbc:sqlite:D:/xxx/data/sqliteDB/demo.dbuse ...
随机推荐
- Outlook 2013 日历/任务本地备份与还原
1.日历: 备份日历:切换到日历项,按如下步骤备份.文件 --> 保存日历 --> 其它选项: 日期范围:指定日期(开始日期:2018/1/1,结束日期:2018/12/31) 详细信息: ...
- 关于SDK_JDK_JRE_JVM的关系
SDK JDK JRE JVM 四者的关系 一:SDK与JDK的关系(可以认为jdk只是sdk的一种子集) SDK是Software Development Kit的缩写,中文意思是“软件开发工具包” ...
- static_assert与assert
C++0x中引入了static_assert这个关键字,用来做编译期间的断言,因此叫做静态断言. 其语法:static_assert(常量表达式,提示字符串). 如果第一个参数常量表达式的值为fals ...
- 第三周博客作业<西北师范大学|李晓婷>
1.助教博客链接:https://www.cnblogs.com/lxt-/MyComments.html 2.学生作业打分要求: https://www.cnblogs.com/nwnu-dai ...
- 解决php -v查看到版本与phpinfo()版本不一致问题
安装p7后发现phpinfo的版本是7.2.12,而php -v查看的却是5.4.16 应该是php.ini的配置文件有问题. 查看文件,有两个 查看cli执行的文件是哪一个? 再查看phpinfo用 ...
- JavaWeb之DButils整理
一.DBUtils介绍 apache 什么是dbutils,它的作用 DBUtils是java编程中的数据库操作实用工具,小巧简单实用. 用前导包!!!DBUtils包!!! 二.DBUtils的三 ...
- sklearn_收入模型
sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...
- freetype 字形解析
目录 freetype 字形解析 字体管理 数据结构 字体抽象 title: freetype 字形解析 date: 2019/3/7 20:17:46 toc: true --- freetype ...
- DNS Tunnel隧道隐蔽通信实验 && 尝试复现特征向量化思维方式检测
1. DNS隧道简介 DNS隧道技术是指利用 DNS协议建立隐蔽信 道,实现隐蔽数据传输.最早是在2004年 DanKaminsky 在 Defcon大会上发布的基于 NSTX 的 DNS隐蔽 隧道工 ...
- HDU 2717(* bfs)
题意是在一个数轴上,每次可以一步到达当前位置数值的 2 倍的位置或者数值 +1 或数值 -1 的位置,给定 n 和 k,问从数值为 n 的位置最少多少步可以到达数值为 k 的位置. 用广搜的方法,把已 ...