目录

1.【报错】java.lang.ClassNotFoundException: org.apache.ibatis.session.SqlSession

2.【报错】org.springframework.web.servlet.DispatcherServlet

3.配置Controller扫描

4.对静态资源放行eclipse和IDEA写法不一样

5.【报错】Did not find handler method for [uri] 

6.【报错】org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

7.【报错】Could not resolve placeholder 'jdbc.driverClass' in string value "${jdbc.driverClass}"

8.在打开的网页中,点击下一页进行翻页时,出现乱码,且无内容显示,是get提交出现错误

9、【报错】使用lombok时报错,找不到get/set方法

10.【报错】Annotation processing seems to be disabled for the project "xxxx". But lombok is on classpath.

11.【报错】使用mybatis-generator时报错Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.4.0:generate (default-cli) on project miaosha: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.4.0:generate failed: Cannot resolve classpath entry: C:\Users\10400\IdeaProjects\miaosha\src\main\resources

12.【报错】Caused by: java.lang.IllegalArgumentException: When allowCredentials is true, allowedOrigins cannot contain the special value "*"since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.

13.【报错】The Bean Validation API is on the classpath but no implementation could be found Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider...

14.【报错】Lock wait timeout exceeded; try restarting transaction  锁表

15.【报错】java.lang.IllegalStateException: Transaction synchronization is not active

16.【报错】java:找不到符号

17.【报错】java.lang.IllegalArgumentException: argument type mismatch

18.【报错】Data truncation: Out of range value for column 'xxx' at row 1


1.【报错】java.lang.ClassNotFoundException: org.apache.ibatis.session.SqlSession

分析:可能是忘记加上mybatis依赖和mybatis-spring

解决:

<dependency>
  <groupId>org.mybatis</groupId>
  <artifactId>mybatis-spring</artifactId>
  <version>${mybatis-spring.version}</version>
</dependency>
<dependency>
  <groupId>org.mybatis</groupId>
  <artifactId>mybatis</artifactId>
  <version>${mybatis.version}</version>
</dependency>

版本使用的是:

<mybatis.version>3.4.1</mybatis.version>
<mybatis-spring.version>1.3.0</mybatis-spring.version>

2.【报错】org.springframework.web.servlet.DispatcherServlet

分析:可能是springmvc包没有导

解决:pom.xml文件里添加以下内容

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>5.0.2.RELEASE</version>
  <scope>compile</scope>
</dependency>

3.配置Controller扫描

eclipse:

<context:component-scan base-package="com.itheima.crm.controller" />

idea: 也是一样,但是包路径可能会显示报错,这时,如果项目不显示报错就先不要管

<context:component-scan base-package="com.itheima.crm.controller" />

4.对静态资源放行eclipse和IDEA写法不一样

eclipse:

<!-- 对静态资源放行  -->
<mvc:resources location="/css/" mapping="/css/**"/>
<mvc:resources location="/js/" mapping="/js/**"/>
<mvc:resources location="/fonts/" mapping="/fonts/**"/>

IDEA:

<!-- 对静态资源放行  -->
<mvc:resources mapping="/css/**" location="/css/"/>
<mvc:resources mapping="/js/**" location="/js/"/>
<mvc:resources mapping="/fonts/**" location="/fonts/"/>

5.【报错】Did not find handler method for [uri] 

解决:

IDEA中,在springmvc.xml文件中加入

<mvc:default-servlet-handler/>

6.【报错】org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

分析:applicationContext-*.xml文件没有被扫描到,查看target文件夹下是否有applicationContext-*.xml文件。

解决:

法1:把applicationContext-*.xml文件放在resources文件夹下,然后在pom.xml文件下加入

<build>
    <resources>
      <!--将resources目录下的配置文件编译进classes文件  -->
      <resource>
        <directory>src/main/resources</directory>
      </resource>
    </resources>
</build>

法2:applicationContext-*.xml文件还是放在mapper文件夹下,在pom.xml文件下加入

<build>
    <resources>
      <!-- maven项目中src源代码下的xml等资源文件编译进classes文件夹,
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.xml</include>
        </includes>
      </resource>
</build>

下面的展示我用的是法1

7.【报错】Could not resolve placeholder 'jdbc.driverClass' in string value "${jdbc.driverClass}"

分析:保证其他写的没有问题,则为配置文件加入ignore-unresolvable="true"即可,默认的设置为false

<!-- 配置 读取properties文件 jdbc.properties -->
<context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true"/>

8.在打开的网页中,点击下一页进行翻页时,出现乱码,且无内容显示,是get提交出现错误

解决:

进入IDEA的安装目录:C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\bin (默认),找到以下两个文件,进入编辑

在每个文件里最末端都加入代码:-Dfile.encoding=UTF-8,重启服务器即可。

9、【报错】使用lombok时报错,找不到get/set方法

分析:使用了注解的方式注入get/set方法,但是因为没有安装lombok插件,所以无法正常解析lombok的注解,尽管导包看起来是正常的(有颜色)如下图所示:

解决:进入File---setting---Plugins---搜索lombok---Install---重启。打开IDEA后,发现get/set方法不再报错

10.【报错】Annotation processing seems to be disabled for the project "xxxx". But lombok is on classpath.

解决:

11.【报错】使用mybatis-generator时报错Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.4.0:generate (default-cli) on project miaosha: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.4.0:generate failed: Cannot resolve classpath entry: C:\Users\10400\IdeaProjects\miaosha\src\main\resources

解决:

注意此处提示的路径名是main\resources,查看相应的文件名是否正确。

note:使用mybatis-generator可以减少工作量,自动生成需要手动编写的crud复杂语句mapping文件和POJO文件。   

前提是先建数据库和表    而且,在application.properties文件中配置mapper文件放置路径:

mybatis.mapper-locations=classpath:mapping/*.xml
相应的mybatis-generator.xml文件为:https://blog.csdn/weixin_42311968/article/details/114179563

生成步骤:

1.

-

2.

3,

4.

12.【报错】Caused by: java.lang.IllegalArgumentException: When allowCredentials is true, allowedOrigins cannot contain the special value "*"since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.

分析:由于跨域访问出现的问题    springboot版本:2.4.2

问题代码:

@CrossOrigin(allowCredentials = "true",allowedHeaders = "*")

解决:

@CrossOrigin(allowCredentials = "true",allowedHeaders = "*",originPatterns = "*")

网友说降低springboot的版本到2.4也会成功,但我这里尝试降低版本以下失败,因为找不到相对应的版本。

13.【报错】The Bean Validation API is on the classpath but no implementation could be found Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider...

解决:修改 hibernate 的 bean依赖版本到 5.2.4.Final

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>5.2.4.Final</version>
</dependency>

14.【报错】Lock wait timeout exceeded; try restarting transaction  锁表

原因:由于其他的线程锁住表

解决:

1)利用 select * from information_schema.innodb_trx; 查询正在运行或者阻塞的线程的线程号trx_mysql_thread_id

2)kill掉线程

kill 线程号;

15.【报错】java.lang.IllegalStateException: Transaction synchronization is not active

原因:如报错信息,事物没有开启

解决:在该方法上加事物注解@Transactional

16.【报错】java:找不到符号

现象:明明所有的类和注解都有,且以前也能正常运行

解决:

方法1:File → invalidate caches...

方法2:Maven → clean & package

17.【报错】java.lang.IllegalArgumentException: argument type mismatch

原因:启动一个写好的controller方法,然后报这个错。是因为相关的配置参数没有写

解决:eg:在body参数前加入 @RequestBody 注解。

18.【报错】Data truncation: Out of range value for column 'xxx' at row 1

原因:数据库定义的字段长度和存储的实际字段长度不匹配

解决:

方法1:修改数据库定义的字段长度

方法2:存储时不要超过数据库定义的字段长度

2022.5.6 update


 

更多推荐

IDEA的JAVA项目中遇到的问题