
SpringBoot
_陌子曦
java开发
展开
-
springboot启动时运行一些代码实现
使用 ApplicationRunner 或 ApplicationRunner 如果您需要在 SpringApplication 启动时运行一些代码,可以实现ApplicationRunner或者CommandLineRunner接口。这两个接口的工作方式是一样的,都提供了一个单独的run方法,它将在SpringApplication.run(...)完成之前调用。 CommandLineRunner接口提供了访问应用程序字符串数组形式参数的方法,而ApplicationRunn...原创 2022-02-10 16:29:16 · 558 阅读 · 0 评论 -
springboot项目输入错误url跳转404页面实现方式
1.第一种方式:如果项目使用了templates模版,直接在模版目录下写error.html即可,无需其他配置 2.第二种方式:通过controller指定404页面 import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.Reque原创 2021-08-19 14:37:56 · 1152 阅读 · 0 评论 -
SpringBoot控制层实现单元测试(基于mock)
1.引入jar包依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-test</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <原创 2021-05-06 17:10:18 · 584 阅读 · 0 评论 -
springboot项目实现项目启动加载数据方法
1.定义一个初始化加载方法类,并实现InitializingBean接口 import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Compo原创 2020-09-16 09:34:29 · 1285 阅读 · 0 评论 -
SpringBoot中添加拦截器,在拦截器中注入其他类的时候出现空指针异常解决办法
首先看拦截器代码@Component public class Intercepter extends HandlerInterceptorAdapter{ @Autowired public ActionRolesReader actionRolesReader; @Override public void postHandle(HttpServletRequest reque...原创 2018-06-14 09:27:50 · 1543 阅读 · 1 评论 -
springboot日志的实现方式(两种log4j2.properties和log4j2.yml)
第一种:基于log4j2.properties 首先pom.xml中导入jar <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.21</version>原创 2018-07-23 14:16:40 · 7812 阅读 · 3 评论 -
springboot实现邮件发送
首先新建一个maven项目 1.在pom.xml中一如jar包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> ...原创 2018-10-30 15:57:01 · 462 阅读 · 0 评论