📃
hlvy
  • 目录
  • 项目地址
  • springboot介绍
  • springboot集成lombok
  • springboot基础配置
    • springboot使用banner
    • springboot读取配置文件
    • springboot访问路径配置和Profile配置说明
  • springboot集成mybatis(xml形式)
  • springboot AOP记录用户操作日志
  • springboot 使用thymeleaf
  • springboot整合Thymeleaf——自定义标签
  • springboot MyBatis配置Druid多数据源
  • springboot 中使用Redis缓存
  • springboot 中使用ehcache缓存
  • springboot使用拦截器-过滤器-servlet-listener
  • springboot中使用异步调用(线程池)
  • springboot中配置定时任务(cron表达式)线程池方式
  • springboot发送邮箱
  • springboot使用swagger2
Powered by GitBook
On this page
  • Spring Boot匹配指定后缀.action .do的路径访问
  • Profile配置

Was this helpful?

  1. springboot基础配置

springboot访问路径配置和Profile配置说明

Previousspringboot读取配置文件Nextspringboot集成mybatis(xml形式)

Last updated 5 years ago

Was this helpful?

Spring Boot匹配指定后缀.action .do的路径访问

(项目地址:)

新建个配置文件MyWebMvcConfigurer

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author : kaifa
 * create at:  2019-10-18  17:07
 * @description: WebMvcConfigurer配置类
 */
@Configuration
public class MyWebMvcConfigurer implements WebMvcConfigurer {
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        //开启路径后缀匹配
        configurer.setUseRegisteredSuffixPatternMatch(true);
    }
    /**
     * 设置匹配*.action后缀请求
     * @param dispatcherServlet
     * @return
     */
    @Bean
    public ServletRegistrationBean servletRegistrationBean(DispatcherServlet dispatcherServlet) {
        ServletRegistrationBean<DispatcherServlet> servletServletRegistrationBean = new ServletRegistrationBean<>(dispatcherServlet);
        servletServletRegistrationBean.addUrlMappings("*.action","*.do");
        return servletServletRegistrationBean;
    }

}

只有后缀是.action 和.do的才能访问controller到

Profile配置

Profile用来针对不同的环境下使用不同的配置文件,多环境配置文件必须以application-{profile}.properties的格式命,其中{profile}为环境标识。比如定义两个配置文件:

  • application-dev.properties:开发环境

    server.port=8080
  • application-prod.properties:生产环境

    server.port=8081

至于哪个具体的配置文件会被加载,需要在application.properties文件中通过spring.profiles.active属性来设置,其值对应{profile}值。

如:spring.profiles.active=dev就会加载application-dev.properties配置文件内容。可以在运行jar文件的时候使用命令java -jar xxx.jar --spring.profiles.active={profile}切换不同的环境配置。

https://github.com/heng1234/springboot2.x/tree/master/boot_banner_yml
下一章:pringboot2.x集成mybatis(druid+xml方式)