Java 项目启动常见报错问题记录
Process finished with exit code 0
清理Maven的org 下 apache 文件夹,让Maven重新下载jar包
或者运行Maven命令,清理jar包
dependency:purge-local-repository
Failed to configure a DataSource
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
翻译:无法配置DataSource:未指定'url'属性,也无法配置嵌入数据源。
报错原因:数据库配置未配置或者不正确
解决方法:
1、项目配置文件中没有配置spring-datasource-url属性或者拼写格式错误
spring:
datasource:
url: jdbc:mysql://localhost:3306/read_data?useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
2、启动类头部声明
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
3、项目的依赖需要配置数据源
解决办法就是在当前工程导入其他工程依赖时,把其它工程里需要配置dataSource的依赖给exclude掉
<dependency>
<groupId>com.xuecheng</groupId>
<artifactId>xc-framework-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</exclusion>
</exclusions>
</dependency>
4、配置 spring-datasource-url的文件没有加载(有些配置了反倒不行)
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
5、resources 文件夹是普通文件夹,需要设置为 Resources root
6、每个 application-xx.properties
文件都需要正确配置(注意名字)
MybatisPlusException: not find
报错原因:entity包下无实例类
Caused by: com.baomidou.mybatisplus.exceptions.MybatisPlusException: not find typeAliasesPackage:classpath*:com/dxjy/pcr/modules/*/entity/*.class
at com.baomidou.mybatisplus.toolkit.PackageHelper.convertTypeAliasesPackage(PackageHelper.java:76)
... 39 common frames omitted
Incorrect integer value
Cause: java.sql.SQLException: Incorrect integer value: 'file' for column 'type' at row 1\n; uncategorized SQLException; SQL state [HY000]; error code [1366]; Incorrect integer value: 'file' for column 'type' at row 1; nested exception is java.sql.SQLException: Incorrect integer value: 'file' for column 'type' at row 1
报错原因:数据库字段和实体类类型不对应
The alias 'xxx' is already mapped to the value '..xxx'.
报错原因:xxx实体的类名冲突了
The port may already be in use or the connector may be misconfigured.
Description:
The Tomcat connector configured to listen on port 8082 failed to start. The port may already be in use or the connector may be misconfigured.
Action:
Verify the connector's configuration, identify and stop any process that's listening on port 8082, or configure this application to listen on another port.
报错原因:8082端口占用
解决办法:
netstat -ano|findstr 8005(端口号)
taskkill /pid 22376 /f (22376为对应的pid)
SprngBoot引用外部jar包和本身日志接口冲突问题解决办法
If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.SimpleLoggerFactory
解决办法:
starter-web 启动依赖中剔除slf4j
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
或者添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
Caused by: java.lang.ClassNotFoundException: Cannot find class: com.dxjy.pcr.entity.SysLogEntity
原因:SysLogEntity 类找不到
Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
在配置springboot+mysql时,会出现"Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required"显示需要需要将sqlSessionFactory依赖注入。
解决方案:在pom.xml文件内添加如下依赖,然后重新刷新一下maven库即可。
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>