展开
拓展 关闭
订阅号推广码
GitHub
视频
公告栏 关闭

spring boot应用常用配置

pom.xml

<!--自动打包-->
<plugin> 
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<!--热更新:ctrl+F9快速重启服务器-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
</dependency>

<!--postman使用内容协商,修改Header/Accept-->
<dependency>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-xml</artifactId>
</dependency>

<!--切换tomcat服务器为jetty-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

<!--开启指标监控-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!--thymeleaf模板中使用shiro标签-->
<dependency>
    <groupId>com.github.theborakompanioni</groupId>
    <artifactId>thymeleaf-extras-shiro</artifactId>
    <version>2.0.0</version>
</dependency>
<!--shiro整合springboot依赖-->
<dependency>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-spring-boot-starter</artifactId>
    <version>1.5.3</version>
</dependency>
<!--shiro缓存-->
<dependency>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-ehcache</artifactId>
    <version>1.5.3</version>
</dependency>

application.yml

# 不拦截resources目录下的静态资源请求,访问时必须加上前缀res:http://localhost:8080/res/bug.jpg
spring:
  mvc:
    static-path-pattern: /res/**

# 默认访问路径:在资源目录下新建一个文件夹haha,将静态文件放到该文件夹下;访问时加上前缀res:http://localhost:8080/bug.jpg 
resources:
    static-locations: [classpath:/haha/]

# 禁用所有静态资源访问
resources:
    add-mappings: false   

# 浏览器中开启请求参数内容协商模式,响应给客户端json:http://localhost:8080/test?format=json
spring:
    contentnegotiation:
        favor-parameter: true  

# 设置请求前缀,请求方式:http://localhost:8080/world/login
server:
  servlet:
    context-path: /world

# 配置thymeleaf模板
spring:
  thymeleaf:
    cache: false
    prefix: classpath:/templates/
    suffix: .html
    encoding: UTF-8
    content-type: text/html
    mode: HTML5

# 文件上传
# maxFileSize 是单个文件大小
# maxRequestSize 是设置总上传的数据大小
spring:
  servlet:
    multipart:
      enabled: true
      max-file-size: 10MB
      max-request-size: 100MB

# 配置数据源
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/test?characterEncoding=utf8&useSSL=true&serverTimezone=UTC
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver

# 指标监控,暴露所有端点信息,以web方式暴露;访问beans:http://localhost:8080/actuator/beans
management:
endpoints:
  enabled-by-default: true 
  web:
    exposure:
      include: '*'  

# 指标监控,禁用所有,开启单个
management:
  endpoints:
    enabled-by-default: false     
  endpoint:
    beans:
      enabled: true     
    health:
      enabled: true

# 配置端口
server:
  port: 80

# 视图解析
spring:
  mvc: 
    view:
      suffix: ".html"

# 开启驼峰命名自动映射
mybatis:
  configuration:
    map-underscore-to-camel-case: true

# 配置日志记录,top.yfly.sb是java和mapper中间的路径
logging:
  level:
   com:
    ychen:
     boot: debug

posted @ 2021-07-13 20:47  DogLeftover  阅读(53)  评论(0编辑  收藏  举报