抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

默认情况下,SpringApplication 将所有命令行选项参数(即以 – 开头的参数,比如 –server.port=9000)转换为属性,并将它们添加到 Spring Environment 中。如之前所述,命令行属性始终优先于其他属性源。 如果您不希望将命令行属性添加到 Environment,可以使用 SpringApplication.setAddCommandLin...

一、引入依赖SpringBoot默认使用slf4j面板日志,所以只需要导入依赖包,它自动会找到实现类。 1234<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j</artifactId&g...

在springboot中对LocalDateTime序列化有好几种方法,但是目前只试过一种方法可用,就是在对象字段上加上注解。全局上生效的目前还不知道该怎么写。怎么写都不对。所以,应该多了解了解底层才能懂的该怎么办。

1
2
3
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty(value = "更新时间", example = "2019-12-15 22:45:58")
private LocalDateTime updateTime;

原因分析

在使用maven-resources-plugin插件时,发现${}做资源替换不生效。怎么设置都不生效。我的设置已经和文档上的一样了还是不生效。

今天终于在一篇博客的启发下,把${}改成@@,这样终于生效了。于是来查找不生效的原因。

原来插件依赖于<resource.delimiter>@</resource.delimiter>这个配置,而springboot把它给改成了@。

那换回来行不行呢?我还是建议不要换回来。因为springboot也需要这个${}占位符用于环境变量注入到实例Bean里。所以,${}要么给插件用,要么给springboot用。

https://www.cnblogs.com/badtree/articles/9145493.html

定义一个config类

1
2
3
4
5
6
7
8
9
10
11
12
@Component
@ConfigurationProperties(prefix = "app-config")
@Data
public class AppConfig {
public static final String USER_HEAD_IMAGE_PATTERN = "/user/header/";
@NotNull
private String userHeaderImg;
@NotNull
private String filePath;
@NotNull
private String imgUrl;
}

这样的意思是,它里面的所有字段都可以在application.properties里进行配置,数据会被注入到配置对象中,在全局中都可以使用

1
2
3
app-config.imgUrl=/home/project/website/user/header/
app-config.userHeaderImg=file:/home/project/website/user/header/
app-config.filePath=http://192.168.1.102:8096\

从原理出发,很多问题都很好解决。注意这3个文件的配置,一般都能配好

Application.java

1
@MapperScan("com.ifkal.demo.**.mapper") // 要配置的是mapper interface所在的包

application.yml

1
2
3
mybatis-plus:
type-aliases-package: com.ifkal.demo.**.entity
mapper-locations: classpath:com/ifkal/demo/**/mapper/xml/*.xml

思路在 springboot 里注册过滤器有两种思路,一种是在 configuration 里提供 FilterRegistrationBean 的 bean. 第二种是使用 @WebFilter 注解,并且注意使用 @ServletComponentScan 扫描包,两种方式注册过滤器。 第一种方法123456789101112131415161718public class LogCos...

关于文档Spring Boot 参考指南提供了 html、pdf 和 epub 格式的文档。最新的副本可在 http://docs.spring.io/spring-boot/docs/current/reference 获取。 在这里查看历史版本 https://docs.spring.io/spring-boot/docs/ 2.x 中文文档https://docshome.gitboo...