https://stackoverflow.com/questions/29958231/can-a-spring-boot-restcontroller-be-enabled-disabled-using-properties

I found a simple solution using @ConditionalOnExpression:

@RestController
@ConditionalOnExpression("${my.controller.enabled:false}")
@RequestMapping(value = "foo", produces = "application/json;charset=UTF-8")
public class MyController {
@RequestMapping(value = "bar")
public ResponseEntity<String> bar(
return new ResponseEntity<>("Hello world", HttpStatus.OK);
}
}

With this annotation added, unless I have

my.controller.enabled=true

in my application.properties file, the controller won't start at all.

You can also use the more convenient:

@ConditionalOnProperty("my.property")

Which behaves exactly as above; if the property is present and "true", the component starts, otherwise it doesn't.

 

RestController 能不能通过配置关闭的更多相关文章

  1. 简介vsftpd及搭建配置 关闭selinux 不能创建文件

    简介vsftpd及搭建配置一.简介 FTP(文件传输协议)全称是:Very Secure FTP Server. Vsftpd是linux类操作系统上运行的ftp服务器软件. vsftp提供三种登陆方 ...

  2. VS 编译太慢了吗?新建解决方案配置关闭一部分项目的编译

    手头的解决方案真大!里面的项目个数达到了 30 个或是 50 个?然而接近一半是单元测试项目和辅助工具.再加上一些不尽如人意的项目优化,编译速度真的是无力吐槽.幸好 Visual Studio 提供了 ...

  3. (五)Spring Boot之@RestController注解和ConfigurationProperties配置多个属性

    一.@RestController和@Controller的区别 @RestController注解相当于@ResponseBody + @Controller合在一起的作用. 如果只是使用@Rest ...

  4. windows Server 2008 IE增强的安全配置关闭方法

    解决方法 开始->管理工具->服务器管理器

  5. 关闭Windows Server 2012的IE增强安全配置

    在Windows Server 2012中,IE的安全性被增强,对于没有加入信任站点的网址会弹出提示框: 微软这样做是为了增强IE的安全性,但是在实际的使用过程中并不是很方便.如果是个人电脑安装了Wi ...

  6. SpringCloud系列——Config 配置中心

    前言 Spring Cloud Config为分布式系统中的外部化配置提供了服务器端和客户端支持.有了配置服务器,您就有了一个中心位置来管理跨所有环境的应用程序的外部属性.本文记录实现一个配置中心.客 ...

  7. SpringBoot中Application开启与关闭

    0.声明 缘由:没有学过或者没有经历SpringBoot的Application运行机制的话,一定会好奇,博主为啥会写一篇关闭开启的博文,是不是好幼稚?(/o(╥﹏╥)o),待我娓娓道来......为 ...

  8. Spring Cloud(十)高可用的分布式配置中心 Spring Cloud Config 中使用 Refresh

    上一篇文章讲了SpringCloudConfig 集成Git仓库,配和 Eureka 注册中心一起使用,但是我们会发现,修改了Git仓库的配置后,需要重启服务,才可以得到最新的配置,这一篇我们尝试使用 ...

  9. VRRP配置与维护手册-1

    http://www.gpxz.com/diannao/hulianwang/80526.html 一  VRRP简介< xmlnamespace prefix ="o" n ...

随机推荐

  1. du 配合sort查看文件夹大小

    du -s * | sort -nr | head 选出排在前面的10个 du -s * | sort -nr | tail 选出排在后面的10个

  2. 解决:perl: warning: Please check that your locale settings

    问题: perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LAN ...

  3. 安装Goland开发工具

    安装Goland开发工具 开发工具: 文本类的编辑器:记事本,notepad,sublime text,atom... ​ 通过命令执行程序 IED:集成开发环境(integrated develop ...

  4. Linux网络——配置网络之iproute家族命令

    Linux网络——配置网络之iproute家族命令 摘要:本文主要学习了iproute家族用来配置网络的命令. ip命令 ip命令用于查看和管理IP地址.接口.路由.隧道等.用来取代ifconfig命 ...

  5. java核心技术第一篇之数据库基础

    01.数据库的概念: 1).数据库的概念:数据库(Database),就是存储数据的仓库. 2).作用:用来存储和管理大量数据的.内部采用了非常便于查询的机制来存储数据,能保证我们在大量数据的情况下 ...

  6. centOS服务器安装mongodb

    1.为服务器添加mongodb的包管理工具,这就相当于在windows中安装npm,以便能用npm安装各种依赖.添加了这个包管理工具,才能在后面对mongodb做一系列操作. touch /etc/y ...

  7. 查找字段的筛选-使用addCustomView

    关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复231或者20161031可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong. ...

  8. [转]Eclipse插件开发之基础篇(6) SWT简介

    原文地址:http://www.cnblogs.com/liuzhuo/archive/2010/09/01/eclipse_plugin_1_3_1.html SWT(Standard Widget ...

  9. mssql sqlserver 数据类型sql_variant简介说明

    转自: http://www.maomao365.com/?p=9712  摘要: 下文讲述sqlserver中sql_variant数据类型定义.赋值.应用的相关说明,如下所示: 实验环境:sql ...

  10. 故障排除指南(TSG)-ORA-01552: Cannot Use System Rollback Segment for Non-System Tablespace (Doc ID 1579215.1)

    Troubleshooting Guide (TSG) - ORA-01552: Cannot Use System Rollback Segment for Non-System Tablespac ...