springboot的配置文件:application.properties

# 日志配置
logging.config=${@logging.config@}
# WEB应用服务器配置
# 监听地址,默认:127.0.0.1
server.address = ${@server.address@}
# 监听端口,默认:8080
server.port = ${@server.port@}
# 应用上下文路径,默认: / 也可以称为项目路径,是构成url地址的一部分。下面有着重解释
server.context-path = ${@server.context-path@}
# 服务器支持的最大连接数,默认:100
server.tomcat.max-connections = ${@server.tomcat.max-connections@}
# 服务器最大新连接的队列大小,默认: 10
server.tomcat.accept-count=${@server.tomcat.accept-count@}
# 服务器最大线程数,默认:100
server.tomcat.max-threads = ${@server.tomcat.max-threads@}

# AOP配置
spring.aop.proxy-target-class=${@spring.aop.proxy-target-class@}
spring.aop.auto=${@spring.aop.auto@}

# 消息中心配置
msg.enabled = ${@msg.enabled@}
msg.client-type = ${@msg.client-type@}
msg.brokers=${@msg.brokers@}

# dubbo 模式:consumer 消费者
dubbo.mode = consumer
# dubbo 应用名
dubbo.consumer.application-name=${@dubbo.consumer.application-name@}
# dubbo 注册中心
dubbo.consumer.registry-address=${@dubbo.consumer.registry-address@}
# dubbo 注解解析扫描包路径
dubbo.consumer.annotation-package=${@dubbo.consumer.annotation-package@}
# dubbo 连接超时时间
dubbo.consumer.timeout = ${@dubbo.consumer.timeout@}
# dubbo 服务端地址
dubbo.consumer.reference-url=${@dubbo.consumer.reference-url@}

#stats.service.enabled = true

spring.upload.fileTypes = gif,png,jpg,xls,xlsx
spring.upload.storage =com.cmos.datamk.web.upload.ONestStorage
[email protected]@
[email protected]@
[email protected]@
[email protected]@
[email protected]@
#是否启用redis集群
[email protected]@
#redis集群ip
[email protected]@
## swagger相关配置
termsOfServiceUrl = @termsOfServiceUrl@
contactUrl = @termsOfServiceUrl@
contactEmail =  @contactEmail@
basePackage =  @basePackage@
##登录拦截器allIP
ALLOW_IP = @ALLOW_IP@

server.context-path:在每个module的application.properties文件都可以配置server.context-path这个属性。默认可以不配置,直接在controller层通过@RequestMapping来设定url的地址路径。

@RestController
@RequestMapping(path = "/user")
public class UserController {
    @Autowired
    private UserServiceImpl userServiceImpl;
    @RequestMapping(value = "/insertUser",method = RequestMethod.POST)
    public String insertUser(HttpServletRequest request) {

        String name = request.getParameter("name");
        String password = request.getParameter("password");
        UserInfo userInfo = new UserInfo();
        userInfo.setId(UUID.randomUUID().toString());
        userInfo.setName(name);
        userInfo.setPassword(password);
        String result = null;
        if (userServiceImpl.inertUserInfo(userInfo) > 0) {
            result= "success";
        }
        return result;
    }
}

如果server.context-path没有配,请求的url地址就是 localhost : port/user/insertUser
如果server.context-path = “/task”, 请求的url地址就是 localhost : port/task/user/insertUser
在 task这个模块下的所有web层的url地址都需要添加server.context-path。
ngnix 分发的时候 server.context-path 起到了很重要的作用,不用考虑controller里的路径了。
最后,每个部署环境的对应的配置文件都分别写一个。把这里面的@@给替换掉。

猜你喜欢

转载自blog.csdn.net/weixin_40197494/article/details/84853721