springboot自定义配置选项查看技巧

在使用springboot的时候,由于它的自动配置的存在,一开始很容易上手进行应用开发,但是等需要进行深度自定义配置的时候,很多人蒙圈,哪些内容可以自定义配置,配置参数是什么等等问题接踵而来,刚好我有个任务要进行springboot tomcat有那些配置参数可以配置的说明,所以就借这个机会告诉大家怎么查看某一个模块的配置参数有哪些。

        首先,springboot的大部分自动配置类都在一个叫spring-boot-autoconfigure-X.x.x.jar包里,如下所示:


tomcat的配置在org.springframework.boot.autoconfigure.web包里的ServerProperties,它包括tomcatjettyundertow的配置都在里面,当然有公用的和具体服务器独立的配置,我们先看下它的类定义:

 



@ConfigurationPropertiesspring 4.x新特性,通过读取配置文件数据来注入我们的实体属性,如ServerProperties就是读取配置文件里server开头的配置选项来进行注入,比如我们在配置文件里配置了 server.port = 1000,则ServerPropertiesport端口就是1000;ServerPropertis的属性就整个应用的web容器的公用配置选项,我们可以看出有哪些。

        接下来看下tomcat的配置有哪些,在同一个类里,我们找到tomcat的类定义,如下图所示:

 

        从上面tomcat定义的属性就可以看出,我们可以配置哪些熟悉,包括我们现在项目进行配置的accesslog配置,我点进Accesslog的定义,就知道怎么在springboot配置文件自定义配置accesslog,如下图:

如果我们要配置accesslogenabled属性,只需要在application.properties文件里定义

Server.tomcat.accesslog.enabled= true;

Tomcat的所有配置选项如下:

server. Port = xxxx

server. Address =

server. contextPath =

server. displayName =

server. servletPath =

server. contextParameters =

server. useForwardHeaders =

server. serverHeader =

server. maxHttpHeaderSize =

server. maxHttpPostSize =

server. connectionTimeout =

server. session.timeout =

server. session.trackingModes =

server. session.persistent =

server.session.storeDir =

server.cookie. name =

server.cookie. domain =

server.cookie. path =

server.cookie. comment =

server.cookie. httpOnly =

server.cookie. secure =

server.cookie. maxAge =

server. ssl. Enabled =

server.ssl. clientAuth =

server.ssl. ciphers =

server.ssl. enabledProtocols =

server.ssl. keyAlias =

server.ssl. keyPassword =

server.ssl. keyStore =

server.ssl. keyStorePassword =

server.ssl. keyStoreType =

server.ssl. keyStoreProvider =

server.ssl. trustStore =

server.ssl. trustStorePassword =

server.ssl. trustStoreType =

server.ssl. trustStoreProvider =

server.ssl. protocol =

server.compression. enabled =

server.compression.mimeTypes =

server.compression.excludedUserAgents =

server.compression.minResponseSize =

server. jspServlet. className =

server.jspServlet. initParameters =

server.jspServlet.registered =

server.tomcat.accesslog.enabled =

server.tomcat.accesslog.pattern =

server.tomcat.accesslog.directory =

server.tomcat.accesslog.prefix =

server.tomcat.accesslog.suffix =

server.tomcat.accesslog.rotate =

server.tomcat.accesslog.renameOnRotate =

server.tomcat.accesslog.requestAttributesEnabled=

server.tomcat.accesslog.buffered =

server.tomcat.internalProxies =

server.tomcat.protocolHeader =

server.tomcat.protocolHeaderHttpsValue =

server.tomcat.portHeader =

server.tomcat.remoteIpHeader=

server.tomcat.basedir =

server.tomcat.backgroundProcessorDelay =

server.tomcat.maxThreads =

server.tomcat.minSpareThreads =

server.tomcat.maxHttpPostSize =

server.tomcat.maxHttpHeaderSize =

server.tomcat.redirectContextRoot =

server.tomcat.uriEncoding =

server.tomcat.maxConnections =

server.tomcat.acceptCount =

server.tomcat.additionalTldSkipPatterns =

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot是一个用于构建独立的、生产级别的Spring应用程序的框架。它提供了许多便捷的功能和特性,其中包括自定义注解配置。 在Spring Boot中,我们可以通过自定义注解来实现一些特定的配置。下面是一个简单的示例来介绍如何自定义注解配置: 1. 首先,创建一个自定义注解类,使用`@interface`关键字来定义注解。例如,我们创建一个名为`@CustomAnnotation`的注解: ```java import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface CustomAnnotation { String value() default ""; } ``` 2. 在需要使用该注解的类上添加注解。例如,我们创建一个名为`CustomClass`的类,并在类上添加`@CustomAnnotation`注解: ```java @CustomAnnotation("customValue") public class CustomClass { // 类的具体实现 } ``` 3. 在Spring Boot的配置类中,使用`@ComponentScan`注解来扫描带有自定义注解的类,并进行相应的配置。例如: ```java @SpringBootApplication @ComponentScan(basePackages = "com.example") public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` 4. 在需要使用自定义注解的地方,可以通过反射获取注解的值,并进行相应的处理。例如,在某个Service类中使用自定义注解: ```java @Service public class CustomService { @Autowired private ApplicationContext applicationContext; public void processCustomAnnotation() { Map<String, Object> customBeans = applicationContext.getBeansWithAnnotation(CustomAnnotation.class); for (Object bean : customBeans.values()) { CustomAnnotation customAnnotation = bean.getClass().getAnnotation(CustomAnnotation.class); String value = customAnnotation.value(); // 处理自定义注解的逻辑 } } } ``` 这样,我们就可以通过自定义注解来实现一些特定的配置。在上述示例中,我们通过自定义注解`@CustomAnnotation`来标记需要进行特定处理的类,并在`CustomService`中通过反射获取带有该注解的类,并进行相应的处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值