1. Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 'dataSource' defined
缺少commons-dbcp.jar、commons-pool.jar这两个包
2. Cannot find class [org.mybatis.spring.SqlSessionFactoryBean] for bean with name 'SqlSessionFactory'
pom.xml增加依赖
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.2</version>
</dependency>
3. No qualifying bean of type “” available
Impl加@Service注解
@Repository(value = "userDao")
该注解是告诉Spring,让Spring创建一个名字叫“userDao”的UserDaoImpl实例。
当Service需要使用Spring创建的名字叫“userDao”的UserDaoImpl实例时,就可以使用@Resource(name = "userDao")注解告诉Spring,Spring把创建好的userDao注入给Service即可。
4. mysql时区问题 mysql的时区错误问题: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one
mysql -u root -p
show variables like '%time_zone%';
set global time_zone = '+8:00';
在jdbc连接的url后面加上serverTimezone=GMT即可解决问题(DBeaver则为编辑连接-连接设置-驱动属性-serverTimezone),如果需要使用gmt+8时区,需要写成GMT%2B8,否则会被解析为空。再一个解决办法就是使用低版本的MySQL jdbc驱动,5.1.28不会存在时区的问题
mysql8.0版本jdbc驱动连接数据库:
1.驱动名字改了,以往版本的是"com.mysql.jdbc.Driver",8.0版本的是"com.mysql.cj.jdbc.Driver"。
2.获得连接时,url的内容需要修改,以往的版本的是"jdbc:mysql://localhost/<数据库名>",8.0版本的是"jdbc:mysql://localhost/<数据库名>?useSSL = false&serverTimezone = UTC&"。
5. log4j不打印日志的问题解决方式一
在使用log4j的时候,必须的jar包。
commons-logging-1.2.jar
log4j-1.2.17.jar
slf4j-log4j12-1.7.21.jar
slf4j-api-1.6.4.jar
6.spring启动找不到spring.liveBeansView.mbeanDomain配置
在项目中的web.xml中添加如下配置:
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>dev</param-value>
</context-param>
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>dev</param-value>
</context-param>
<context-param>
<param-name>spring.liveBeansView.mbeanDomain</param-name>
<param-value>dev</param-value>
</context-param>
7.静态文件引用失败,使用项目名+静态文件全路径
8.springboot下js引用路径:(js要放在src/main/resources/static下)
1.<script src="${pageContext.request.contextPath}/scripts/jquery-1.8.3.min.js"></script>
2.<script src="/scripts/jquery-3.0.0.js"></script>
9.打包出错
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test (default-test) on project chapter16: There are test failures.
mvn clean package -Dmaven.test.skip=true
pom.xml文件 <!-- 打包跳过测试 -->
<skipTests>true</skipTests>
10.This application has no explicit mapping for /error, so you are seeing this as a fallback.
出现这个异常说明了跳转页面的url无对应的值.
原因1:
Application启动类的位置不对.要将Application类放在最外侧,即包含所有子包(比如你的groupId是com.google,子包就是所谓的com.google.xxx,所以要将Application放在com.google包下。)
spring-boot会自动加载启动类所在包下及其子包下的所有组件(加上@SpringBootApplication(scanBasePackages = { "com.wangmeng.simpledemo.*" })扫描到controller)
原因2:
在springboot的配置文件:application.yml或application.properties中关于视图解析器的配置问题:
当pom文件下的spring-boot-starter-paren版本高时使用:spring.mvc.view.prefix/spring.mvc.view.suffix
当pom文件下的spring-boot-starter-paren版本低时使用::spring.view.prefix/spring.view.suffix
原因3:
控制器的URL路径书写问题:
@RequestMapping(“xxxxxxxxxxxxxx”) ,实际访问的路径与”xxx”不符合
11.java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
在根目录下写一个springboot的启动类:写个App.class,再在test测试类跑起来
12.eclipse中maven项目找不到Maven Dependencies解决办法
首先若你不是package explorer视图:解决办法:
只需选中这个视图:window->show view->other->java->package explorer
若还没有则用下述办法解决。
若你是package explorer视图:解决办法:
1. 选中项目 --> 右键 --> Maven --> Disable Maven Nature
此时,右键菜单中将隐藏【Maven】菜单选项
2. 选中项目 --> 右键 --> Configure --> Convert to Maven project.
3. 选中项目-->右键-->Properties-->Deployment Assembly --> Add --> Java Build Path Entries 下即可找到 Maven Dependencies
或者打开.classpath文件,添加如下内容:
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
13.-source 1.7 中不支持 lambda 表达式(请使用 -source 8 或更高版本以启用 lambda 表达式)
maven的Setting.xml里面的java 版本
14.WARN 9104 --- [io-8080-exec-10] o.s.web.servlet.PageNotFound : Request method 'POST' not supported
requestmapping的path大小写一致,json与对象的字段一致
15.java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;
servlet-api.jar版本问题
16.this compilation unit is not on the build path of a java project
17.在SSM框架中,写controller,使用@value注入properties文件中的key,取不到值
出现问题原因:spring和springmvc父子容器问题,springmvc先初始化加载,而扫描控制器的包,在springmvc.xml文件中,导致在controller中使用@value注解,注入不进去,而在service层可以使用.
解决办法(配置在xxx-servlet.xml中,而不是web.xml或xxxServer.spring.xml):
<context:property-placeholder ignore-unresolvable="true" location="classpath:my.properties" />
在springmvc.xml中,重新配置一遍,properties扫描,即可解决.
springmvc就是管理controller对象的容器,spring就是管理service和dao的容器,所以我们在springmvc的配置文件里配置的扫描路径就是controller的路径,而spring的配置文件里自然配的就是service和dao的路径
web.xml和XXX-servlet.xml初始化上下文关系和区别
18.@Autowired找不到bean,要配置(xml配置或加注解@Bean@Component等等)
new对象是传统方式
19.项目配置上下文参数:
1.使用xml(build时从profile写值到key-value),启动服务时初始化方法(web.xml定义servlet)初始化
2.使用properties(build时从profile写值到key-value),在xxx-servlet.xml或applicationcontext.xml中<context:property-placeholder ignore-unresolvable="true" location="classpath:my.properties" />
20.Spring项目配置文件:
1.web.xml
web.xml文件详解(转)
2.applicationContext.xml
Spring中,applicationContext.xml 配置文件在web.xml中的配置详解
3.spring-servlet.xml
浅谈配置文件:spring-servlet.xml(spring-mvc.xml) 与 applicationContext.xml
springMVC(二)web.xml和springmvc-servlet.xml配置
21.Spring AOP
利用spring mvc AOP进行日志管理 (采用注解@AspectJ)
22.classpath
1.src不是classpath, WEB-INF/classes,lib才是classpath,WEB-INF/ 是资源目录, 客户端不能直接访问。
2.WEB-INF/classes目录存放src目录java文件编译之后的class文件,xml、properties等资源配置文件,这是一个定位资源的入口。
3.引用classpath路径下的文件,只需在文件名前加classpath:
<param-value>classpath:applicationContext-*.xml</param-value>
<!-- 引用其子目录下的文件,如 -->
<param-value>classpath:context/conf/controller.xml</param-value>
4.lib和classes同属classpath,两者的访问优先级为: lib>classes。
5.classpath 和 classpath* 区别:
classpath:只会到你的class路径中查找找文件;
classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找。
23.WEB-INF目录与META-INF目录的作用
24.打印mybatis执行的sql
1.SpringBoot,修改application.yml文件
mybatis:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
2.普通spring工程
修改日志配置:
log4j.logger.com.ibatis=DEBUG
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
log4j.logger.Java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
3.普通spring工程,在mybatis.config.xml中增加如下配置:
<configuration>
<settings>
<setting name="logImpl" value="STDOUT_LOGGING" />
</settings>
</configuration>
25.Maven打包失败,报错:Failed to collect dependencies...
错误如下:
Failed to execute goal on ...: Could not resolve dependencies for project xxx.xxx.xxx.xx:jar:...: Failed to collect dependencies for [xxx.xxx.xxx.xxx:jar:... (compile), ......]
解决方法:先打包父工程,然后在打包子模块就可以解决以上问题。
26.META-INF/spring.factories作用
EnableAutoConfiguration注解的工作原理
27.SpringBoot多数据源配置
DataSourceBuilder.create().build()使用 Spring Boot配置多个DataSource - 廖雪峰的官方网站
https://www.jianshu.com/p/f728e8c131a9
Springboot2.x整合mybatis多数据源(注解完整版,亲测成功) mybatis
springboot+druid+mybatis plus的多数据源配置 纯粹多数据源
springboot简易集成mybatisPlus+多数据源 主从
springboot+mybatis-plus+多数据源配置,实现分表分库的数据访问 纯粹多数据源
Druid连接池配置 alibaba社区
druid 使用与配置 ver1.1.9 监控配置 Druid监控功能的深入使用与配置-基于SpringBoot-完全使用 .properties配置文件
https://blog.csdn.net/qq_42235671/article/details/84592028 ver1.1.10
Spring Boot(18)——使用Alibaba Druid DataSource
28.H2数据库Database may be already in use: null
h2默认单连接,多个用户则使用TCP连接,如(加上红字部分)
url: jdbc:h2:tcp://localhost/D:\databases\h2data\mybatisplus
29.swagger-ui.html 404
解决swagger2集成问题,404,1弹窗问题,2启动项目报错
30.Spring5.X后WebMvcConfigurerAdapter类被弃用
WebMvcConfigurerAdapter类被弃用后的两种选择
31.fastJson与jackson性能对比
fastJson与jackson性能对比_Belief的编码生涯-CSDN博客
32.SpringBoot2 HandlerInterceptor拦截器失效
SpringBoot2.x整合HandlerInterceptor拦截器(1-定义拦截器)
33.java.lang.IllegalStateException: Connection pool shut down
使用HttpClient连接池出现---java.lang.IllegalStateException: Connection pool shut down
34.java项目获取文件编码
https://code.google.com/archive/p/juniversalchardet/
35.springboot2.3 javax.validation.constraints找不到异常
36.Spring Boot 排除自动配置的 4 种方法,关键时刻很有用!
38.Jackson之LocalDateTime转换,无需改实体类
39.SpringBoot mbeanExporter重复加载报错
40.Spring Cloud Gateway网关XSS过滤
42.Spring boot webflux 里的feign如何动态添加来自request的header?
43.开启hystrix:feign.hystrix.enabled=true时, RequestContextHolder.getRequestAttributes()为空
45.从@Async案例找到Spring框架的bug:exposeProxy=true不生效原因大剖析+最佳解决方案