1.1Spring Boot 环境配置和常用注解

Wesley13
• 阅读 507

Spring Boot常用注解:
@Service: 注解在类上,表示这是一个业务层bean
@Controller:注解在类上,表示这是一个控制层bean
@Repository: 注解在类上,表示这是一个数据访问层bean
@Component: 注解在类上,表示通用bean ,value不写默认就是类名首字母小写
@Autowired:按类型注入.默认属性required= true;当不能确定 Spring 容器中一定拥有某个类的Bean 时, 可以在需要自动注入该类 Bean 的地方可以使用 @Autowired(required = false), 这等于告诉Spring:在找不到匹配Bean时也不抛出BeanCreationException 异常。@Autowired 和 @Qualifier 结合使用时,自动注入的策略就从 byType 转变byName 了。@Autowired可以对成员变量、方法以及构造函数进行注释,而 @Qualifier 的标注对象是成员变量、方法入参、构造函数入参。正是由于注释对象的不同,所以 Spring 不将 @Autowired 和 @Qualifier 统一成一个注释类。
@Resource: 按名称装配

区别:

@Resource默认按照名称方式进行bean匹配,@Autowired默认按照类型方式进行bean匹配

@Resource(importjavax.annotation.Resource;)是J2EE的注解,@Autowired(importorg.springframework.beans.factory.annotation.Autowired;)是Spring的注解
@Configuration:注解在类上,表示这是一个IOC容器,相当于spring的配置文件,java配置的方式。 IOC容器的配置类一般与 @Bean 注解配合使用,用 @Configuration 注解类等价与 XML 中配置 beans,用@Bean 注解方法等价于 XML 中配置 bean。
@Bean: 注解在方法上,声明当前方法返回一个Bean

@Scope:注解在类上,描述spring容器如何创建Bean实例。

(1)singleton: 表示在spring容器中的单例,通过spring容器获得该bean时总是返回唯一的实例

(2)prototype:表示每次获得bean都会生成一个新的对象

(3)request:表示在一次http请求内有效(只适用于web应用)

(4)session:表示在一个用户会话内有效(只适用于web应用)

(5)globalSession:表示在全局会话内有效(只适用于web应用)

在多数情况,我们只会使用singleton和prototype两种scope,如果未指定scope属性,默认为singleton
@Value:注解在变量上,从配置文件中读取。

例如:@Value(value = “#{message}”)

@ConfigurationProperties   赋值,将注解转换成对象。给对象赋值。车险项目:HttpClientSetting类

@Profile:注解在方法类上在不同情况下选择实例化不同的Bean特定环境下生效!!!!!!!!!!!!!!!!!

@SpringBootApplication:@SpringBootApplication=@ComponentScan+@Configuration+@EnableAutoConfiguration:约定优于配置

@EnableAutoConfiguration启用 Spring 应用程序上下文的自动配置,试图猜测和配置您可能需要的bean。自动配置类通常采用基于你的classpath 和已经定义的 beans 对象进行应用。被 @EnableAutoConfiguration 注解的类所在的包有特定的意义,并且作为默认配置使用。通常推荐将 @EnableAutoConfiguration 配置在 root 包下,这样所有的子包、类都可以被查找到。

@ComponentScan:注解在类上,扫描标注了@Controller等注解的类,注册为bean 。@ComponentScan 为 @Configuration注解的类配置组件扫描指令。@ComponentScan 注解会自动扫描指定包下的全部标有 @Component注解的类,并注册成bean,当然包括 @Component下的子注解@Service、@Repository、@Controller。 

@RestController @RestController 是一个结合了 @ResponseBody 和 @Controller 的注解

@Responsebody 注解表示该方法的返回的结果直接写入 HTTP 响应正文(ResponseBody)中,一般在异步获取数据时使用,通常是在使用 @RequestMapping 后,返回值通常解析为跳转路径,加上@Responsebody 后返回结果不会被解析为跳转路径,而是直接写入HTTP 响应正文中。

@RequestBody

@PathVariable

@RequestParam

两者的作用都是将request里的参数的值绑定到contorl里的方法参数里的,区别在于,URL写法不同。

当请求参数username不存在时会有异常发生,可以通过设置属性required=false解决,例如:

@RequestParam(value="username",required=false)

使用@RequestParam时,URL是这样的:http://host:port/path?参数名=参数值

使用@PathVariable时,URL是这样的:http://host:port/path/参数值

不写的时候也可以获取到参数值,但是必须名称对应。参数可以省略不写

@RequestMapping  和请求报文是做对应的   
  a:value,指定请求的地址 
  b:method 请求方法类型 这个不写的话,自适应:get或者post
  c:consumes 请求的提交内容类型 
  d:produces 指定返回的内容类型 仅当request请求头中的(Accept)类型中包含该指定类型才返回
  e: params 指定request中必须包含某些参数值 
  f:headers 指定request中必须包含指定的header值

g: name  指定映射的名称  

 @RequestMapping(method = RequestMethod.GET)

 @RequestMapping(method = RequestMethod.POST)

 @RequestMapping(method = RequestMethod.PUT)

 @RequestMapping(method = RequestMethod.DELETE)

 当然也可以使用

 @GetMapping

 @PostMapping

 @PutMapping

 @DeleteMapping 这与上面的是一样的效果

@EnablCaching @EnableCaching注解是spring framework中的注解驱动的缓存管理功能。自spring版本3.1起加入了该注解。如果你使用了这个注解,那么你就不需要在XML文件中配置cache manager了。

@suppresswarnings 抑制警告

@Modifying 如果是增,改,删加上此注解

1:方法的返回值应该是int,表示更新语句所影响的行数。

2:在调用的地方必须加事务,没有事务不能正常执行。@Transactional  事务注解

@Query 自定义查询语句 JPQL

Spring Boot常用配置:

一、Spring Boot 启动注解说明

@SpringBootApplication开启了Spring的组件扫描和Spring Boot的自动配置功能。实际上, @SpringBootApplication将三个有用的注解组合在了一起。

  • Spring的@Configuration:标明该类使用Spring基于Java的配置。虽然本书不会写太多配置,但我们会更倾向于使用基于Java而不是XML的配置。
  • Spring的@ComponentScan:启用组件扫描,这样你写的Web控制器类和其他组件才能被自动发现并注册为Spring应用程序上下文里的Bean。默认扫描@SpringBootApplication 所在类的同级目录以及它的子目录。本章稍后会写一个简单的Spring MVC控制器,使用@Controller进行注解,这样组件扫描才能找到它。
  • Spring Boot 的 @EnableAutoConfiguration: 这 个 不 起 眼 的 小 注 解 也 可 以 称 为@Abracadabra①,就是这一行配置开启了Spring Boot自动配置的魔力,让你不用再写成篇的配置了。

在Spring Boot的早期版本中,你需要在ReadingListApplication类上同时标上这三个注解,但从Spring Boot 1.2.0开始,有@SpringBootApplication就行了。

二、Bean的scope

scope描述了spring容器如何新建bena的实例,spring的scope有以下几种,通过@Scope注解来实现

  • Singleton:一个spring容器中只有一个bena的实例,此为spring的默认配置,全容器共享一个实例的bean。
  • Prototype:每次调用新建一个bean的实例。
  • Request:web项目中,给每一个http request新建一个Bean实例。
  • Session :web项目中,给每一个http session新建一个实例。
  • GlobalSession:这个只在portal应用中有用,给每一个global http session新建一个bean实例。

另外,在spring batch中还有一个Scope是使用@StepScope,用在批处理中。

三、Bean的初始化和销毁

  在我们实际开发的时候,经常会遇到在bean使用之前或者之后做一些必要的操作,spring 对bean的生命周期的操作提供了支持。在使用java配置和注解配置下提供如下两种方式:

  • java配置方式:使用@Bean的initMethod和destroyMethod(相当于xml配置的init-method和destory-method)
  • 注解方式:利用JSR-250的@PostConstruct和@PreDestroy

四、Spring EL和资源调用

  spring EL-Spring表达式语言,支持在xml和注解中使用表达式,类似于jsp的EL表达式语言。
  spring开发中经常涉及调用各种资源的情况,包含普通文件,网址,配置文件,系统环境变量等,我们可以使用  spring表达式语言实现资源的注入。
  spring主要在注解@Vavle的参数中使用表达式。
下面演示一下几种情况:

  • 注入普通字符串
  • 注入操作系统属性
  • 注入表达式运算结果
  • 注入其他Bean的属性
  • 注入文件内容
  • 注入网址内容
  • 注入属性文件

五、Profile

1、基础练习

Profile为在不同环境下使用不同的配置提供了支持(开发环境下的配置和生产环境下的配置不同,比如数据库)

  • 通过设定Enviroment的ActiveProfiles来设定当前context需要使用的配置环境。在开发中使用@Profile注解类或者方法,达到在不同情况下选择实例化不同的Bean
  • 通过设定jvm的spring.profiles.active参数来设置配置环境
  • Web项目设置在Servlet的context parameter中

1、定义一个bean

1.1Spring Boot 环境配置和常用注解

public class CustomProfileBean {
    private String content;
     
    public CustomProfileBean(String content) {
        super();
        this.content = content;
    }
 
    public String getContent() {
        return content;
    }
 
    public void setContent(String content) {
        this.content = content;
    }
}

1.1Spring Boot 环境配置和常用注解

2、配置

1.1Spring Boot 环境配置和常用注解

@Configuration
public class CustomProfileConfig {
    @Bean
    @Profile("dev")//Profile为dev时实例化devCustomProfileBean
    public CustomProfileBean devCustomProfileBean(){
        return new CustomProfileBean("from development pfofile");
    }
    
    @Bean
    @Profile("prod")//Profile为prod时实例化prodCustomProfileBean
    public CustomProfileBean prodCustomProfileBean(){
        return new CustomProfileBean("from  production profile");
    }

}

1.1Spring Boot 环境配置和常用注解

3、启动运行

1.1Spring Boot 环境配置和常用注解

public class CustomProfileMain {

    public static void main(String [] args){
        //AnnotationConfigApplicationContext作为spring容器,接受一个配置类作为参数
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        //先将活动的Profile设置为prod
        context.getEnvironment().setActiveProfiles("prod");
        //后置注册Bean配置类,不然会报bean未定义的错误
        context.register(CustomProfileConfig.class);
        //刷新容器
        context.refresh();
        CustomProfileBean demoBean = context.getBean(CustomProfileBean.class);
        System.out.println(demoBean.getContent());
        context.close();
    }
}

2、日志信息的配置

logback-spring.xml

1.1Spring Boot 环境配置和常用注解

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true"><!-- debug="true"设置调试模式 -->
    <!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径,文件要以logback-spring.xml命名-->
    <springProfile name="test">
        <property name="catalina.base" value="/home/webapp/logs/spring-boot" />
    </springProfile>
    <springProfile name="prod">
        <property name="catalina.base" value="/app/webapp/logs/spring-boot" />
    </springProfile>
    <springProfile name="dev">
        <property name="catalina.base" value="H:/logs/spring-boot" />
    </springProfile>

    <!--<springProperty scope="context" name="catalina.base" source="catalina.base"/>-->

    <!-- 日志地址 -->
    <!--<property name="catalina.base" value="H:/logs"></property>-->

    <!-- 控制台输出 -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} 耗时:%r 日志来自:%logger{50} 日志类型: %-5p 日志内容:%m%n</pattern>
        </encoder>
    </appender>
    <!-- 按照每天生成日志文件 -->
    <appender name="DEFAULT-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${catalina.base}/logs/common-default.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--日志文件输出的文件名 -->
            <FileNamePattern>${catalina.base}/logs/common-default-%d{yyyy-MM-dd}.log</FileNamePattern>
            <!--日志文件保留天数 -->
            <MaxHistory>30</MaxHistory>
        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
        </encoder>
        <!--日志文件最大的大小 -->
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>10MB</MaxFileSize>
        </triggeringPolicy>
    </appender>
    <!-- 按照每天生成日志文件 -->   
    <appender name="INFO-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${catalina.base}/logs/info-log.log</File>  
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--日志文件输出的文件名 -->
            <FileNamePattern>${catalina.base}/logs/info-log-%d{yyyy-MM-dd}.log</FileNamePattern>
            <!--日志文件保留天数 -->
            <MaxHistory>30</MaxHistory>
        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <!-- 格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
        </encoder>
        <!--日志文件最大的大小 -->
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>10MB</MaxFileSize>
        </triggeringPolicy>
    </appender>

    <logger name="com.google.code.yanf4j"  level="ERROR" />

    <!-- show parameters for hibernate sql 专为 Hibernate 定制 -->
    <logger name="org.hibernate.type.descriptor.sql.BasicBinder"  level="TRACE" />
    <logger name="org.hibernate.type.descriptor.sql.BasicExtractor"  level="DEBUG" />
    <logger name="org.hibernate.SQL" level="DEBUG" />
    <logger name="org.hibernate.engine.QueryParameters" level="DEBUG" />
    <logger name="org.hibernate.engine.query.HQLQueryPlan" level="DEBUG" />

    <!--myibatis log configure-->
    <logger name="org.apache.ibatis" level="DEBUG"/>
    <logger name="java.sql.Connection" level="DEBUG"/>
    <logger name="java.sql.Statement" level="DEBUG"/>
    <logger name="java.sql.PreparedStatement" level="DEBUG"/>

    <logger name="net.rubyeye.xmemcached" level="INFO"/>
    <logger name="org.springframework" level="INFO"/>
    <logger name="net.sf.ehcache" level="INFO"/>

    <logger name="org.apache.zookeeper"  level="INFO" />

    <!-- 指定某一个包或者某一个类的打印级别以及是否传入root进行打印 -->
    <!-- addtivity:是否向上级loger传递打印信息。默认是true。-->
    <!-- <loger>可以包含零个或多个<appender-ref>元素,标识这个appender将会添加到这个loger。-->
    <!-- name:用来指定受此loger约束的某一个包或者具体的某一个类。-->
    <!-- level:
            用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,还有一个特俗值INHERITED或者同义词NULL,代表强制执行上级的级别。
            如果未设置此属性,那么当前loger将会继承上级的级别。-->
    <!-- 为所有开头为dao的类打印sql语句 -->
    <!-- <logger name="dao" level="DEBUG">
        <appender-ref ref="INFO-APPENDER" />
    </logger> -->
    <logger name="com.only.mate" level="DEBUG" additivity="true">
        <appender-ref ref="INFO-APPENDER" />
    </logger>
    <!-- 也是<loger>元素,但是它是根loger。只有一个level属性,应为已经被命名为"root". -->
    <root level="DEBUG">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="DEFAULT-APPENDER"/>
    </root>

</configuration>

3、Java代码中根据系统环境处理逻辑

创建一个服务,实现ApplicationContextAware接口

1.1Spring Boot 环境配置和常用注解

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

@Service
public class CustomProfileService implements ApplicationContextAware{
    private ApplicationContext applicationContext = null;
    
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public void doSomething() {
        //获取当前系统环境
        String[] springActives = applicationContext.getEnvironment().getActiveProfiles();
        String springActive = "";
        if(springActives.length > 0) {
            springActive = springActives[0];
        }else {
            springActive = applicationContext.getEnvironment().getDefaultProfiles()[0];
        }
        System.out.println("当前的开发环境:"+ springActive);
    }
}

1.1Spring Boot 环境配置和常用注解

配置类

1.1Spring Boot 环境配置和常用注解

@Configuration
@ComponentScan(basePackages="com.only.mate.springboot.basic.profile")
public class CustomProfileConfig {
    @Bean
    @Profile("dev")//Profile为dev时实例化devCustomProfileBean
    public CustomProfileBean devCustomProfileBean(){
        return new CustomProfileBean("from development pfofile");
    }
    
    @Bean
    @Profile("prod")//Profile为prod时实例化prodCustomProfileBean
    public CustomProfileBean prodCustomProfileBean(){
        return new CustomProfileBean("from  production profile");
    }

}

1.1Spring Boot 环境配置和常用注解

启动类

1.1Spring Boot 环境配置和常用注解

public class CustomProfileMain {

    public static void main(String [] args){
        //AnnotationConfigApplicationContext作为spring容器,接受一个配置类作为参数
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        //先将活动的Profile设置为prod
        context.getEnvironment().setActiveProfiles("prod");
        //后置注册Bean配置类,不然会报bean未定义的错误
        context.register(CustomProfileConfig.class);
        //刷新容器
        context.refresh();
        CustomProfileBean customProfileBean = context.getBean(CustomProfileBean.class);
        System.out.println(customProfileBean.getContent());
        
        CustomProfileService customProfileService = context.getBean(CustomProfileService.class);
        customProfileService.doSomething();
        
        context.close();
    }
}

 Spring Boot常用配置参数(application.properties)

mvc

  • spring.mvc.async.request-timeout
    设定async请求的超时时间,以毫秒为单位,如果没有设置的话,以具体实现的超时时间为准,比如tomcat的servlet3的话是10秒.

  • spring.mvc.date-format
    设定日期的格式,比如dd/MM/yyyy.

  • spring.mvc.favicon.enabled
    是否支持favicon.ico,默认为: true

  • spring.mvc.ignore-default-model-on-redirect
    在重定向时是否忽略默认model的内容,默认为true

  • spring.mvc.locale
    指定使用的Locale.

  • spring.mvc.message-codes-resolver-format
    指定message codes的格式化策略(PREFIX_ERROR_CODE,POSTFIX_ERROR_CODE).

  • spring.mvc.view.prefix
    指定mvc视图的前缀.

  • spring.mvc.view.suffix
    指定mvc视图的后缀.

messages

  • spring.messages.basename
    指定message的basename,多个以逗号分隔,如果不加包名的话,默认从classpath路径开始,默认: messages

  • spring.messages.cache-seconds
    设定加载的资源文件缓存失效时间,-1的话为永不过期,默认为-1

  • spring.messages.encoding
    设定Message bundles的编码,默认: UTF-8

mobile

  • spring.mobile.devicedelegatingviewresolver.enable-fallback
    是否支持fallback的解决方案,默认false

  • spring.mobile.devicedelegatingviewresolver.enabled
    是否开始device view resolver,默认为: false

  • spring.mobile.devicedelegatingviewresolver.mobile-prefix
    设定mobile端视图的前缀,默认为:mobile/

  • spring.mobile.devicedelegatingviewresolver.mobile-suffix
    设定mobile视图的后缀

  • spring.mobile.devicedelegatingviewresolver.normal-prefix
    设定普通设备的视图前缀

  • spring.mobile.devicedelegatingviewresolver.normal-suffix
    设定普通设备视图的后缀

  • spring.mobile.devicedelegatingviewresolver.tablet-prefix
    设定平板设备视图前缀,默认:tablet/

  • spring.mobile.devicedelegatingviewresolver.tablet-suffix
    设定平板设备视图后缀.

  • spring.mobile.sitepreference.enabled
    是否启用SitePreferenceHandler,默认为: true

view

  • spring.view.prefix
    设定mvc视图的前缀.

  • spring.view.suffix
    设定mvc视图的后缀.

resource

  • spring.resources.add-mappings
    是否开启默认的资源处理,默认为true

  • spring.resources.cache-period
    设定资源的缓存时效,以秒为单位.

  • spring.resources.chain.cache
    是否开启缓存,默认为: true

  • spring.resources.chain.enabled
    是否开启资源 handling chain,默认为false

  • spring.resources.chain.html-application-cache
    是否开启h5应用的cache manifest重写,默认为: false

  • spring.resources.chain.strategy.content.enabled
    是否开启内容版本策略,默认为false

  • spring.resources.chain.strategy.content.paths
    指定要应用的版本的路径,多个以逗号分隔,默认为:[/**]

  • spring.resources.chain.strategy.fixed.enabled
    是否开启固定的版本策略,默认为false

  • spring.resources.chain.strategy.fixed.paths
    指定要应用版本策略的路径,多个以逗号分隔

  • spring.resources.chain.strategy.fixed.version
    指定版本策略使用的版本号

  • spring.resources.static-locations
    指定静态资源路径,默认为classpath:[/META-INF/resources/,/resources/, /static/, /public/]以及context:/

multipart

  • multipart.enabled
    是否开启文件上传支持,默认为true

  • multipart.file-size-threshold
    设定文件写入磁盘的阈值,单位为MB或KB,默认为0

  • multipart.location
    指定文件上传路径.

  • multipart.max-file-size
    指定文件大小最大值,默认1MB

  • multipart.max-request-size
    指定每次请求的最大值,默认为10MB

freemarker

  • spring.freemarker.allow-request-override
    指定HttpServletRequest的属性是否可以覆盖controller的model的同名项

  • spring.freemarker.allow-session-override
    指定HttpSession的属性是否可以覆盖controller的model的同名项

  • spring.freemarker.cache
    是否开启template caching.

  • spring.freemarker.charset
    设定Template的编码.

  • spring.freemarker.check-template-location
    是否检查templates路径是否存在.

  • spring.freemarker.content-type
    设定Content-Type.

  • spring.freemarker.enabled
    是否允许mvc使用freemarker.

  • spring.freemarker.expose-request-attributes
    设定所有request的属性在merge到模板的时候,是否要都添加到model中.

  • spring.freemarker.expose-session-attributes
    设定所有HttpSession的属性在merge到模板的时候,是否要都添加到model中.

  • spring.freemarker.expose-spring-macro-helpers
    设定是否以springMacroRequestContext的形式暴露RequestContext给Spring’s macro library使用

  • spring.freemarker.prefer-file-system-access
    是否优先从文件系统加载template,以支持热加载,默认为true

  • spring.freemarker.prefix
    设定freemarker模板的前缀.

  • spring.freemarker.request-context-attribute
    指定RequestContext属性的名.

  • spring.freemarker.settings
    设定FreeMarker keys.

  • spring.freemarker.suffix
    设定模板的后缀.

  • spring.freemarker.template-loader-path
    设定模板的加载路径,多个以逗号分隔,默认: ["classpath:/templates/"]

  • spring.freemarker.view-names
    指定使用模板的视图列表.

velocity

  • spring.velocity.allow-request-override
    指定HttpServletRequest的属性是否可以覆盖controller的model的同名项

  • spring.velocity.allow-session-override
    指定HttpSession的属性是否可以覆盖controller的model的同名项

  • spring.velocity.cache
    是否开启模板缓存

  • spring.velocity.charset
    设定模板编码

  • spring.velocity.check-template-location
    是否检查模板路径是否存在.

  • spring.velocity.content-type
    设定ContentType的值

  • spring.velocity.date-tool-attribute
    设定暴露给velocity上下文使用的DateTool的名

  • spring.velocity.enabled
    设定是否允许mvc使用velocity

  • spring.velocity.expose-request-attributes
    是否在merge模板的时候,将request属性都添加到model中

  • spring.velocity.expose-session-attributes
    是否在merge模板的时候,将HttpSession属性都添加到model中

  • spring.velocity.expose-spring-macro-helpers
    设定是否以springMacroRequestContext的名来暴露RequestContext给Spring’s macro类库使用

  • spring.velocity.number-tool-attribute
    设定暴露给velocity上下文的NumberTool的名

  • spring.velocity.prefer-file-system-access
    是否优先从文件系统加载模板以支持热加载,默认为true

  • spring.velocity.prefix
    设定velocity模板的前缀.

  • spring.velocity.properties
    设置velocity的额外属性.

  • spring.velocity.request-context-attribute
    设定RequestContext attribute的名.

  • spring.velocity.resource-loader-path
    设定模板路径,默认为: classpath:/templates/

  • spring.velocity.suffix
    设定velocity模板的后缀.

  • spring.velocity.toolbox-config-location
    设定Velocity Toolbox配置文件的路径,比如 /WEB-INF/toolbox.xml.

  • spring.velocity.view-names
    设定需要解析的视图名称.

thymeleaf

  • spring.thymeleaf.cache
    是否开启模板缓存,默认true

  • spring.thymeleaf.check-template-location
    是否检查模板路径是否存在,默认true

  • spring.thymeleaf.content-type
    指定Content-Type,默认为: text/html

  • spring.thymeleaf.enabled
    是否允许MVC使用Thymeleaf,默认为: true

  • spring.thymeleaf.encoding
    指定模板的编码,默认为: UTF-8

  • spring.thymeleaf.excluded-view-names
    指定不使用模板的视图名称,多个以逗号分隔.

  • spring.thymeleaf.mode
    指定模板的模式,具体查看StandardTemplateModeHandlers,默认为: HTML5

  • spring.thymeleaf.prefix
    指定模板的前缀,默认为:classpath:/templates/

  • spring.thymeleaf.suffix
    指定模板的后缀,默认为:.html

  • spring.thymeleaf.template-resolver-order
    指定模板的解析顺序,默认为第一个.

  • spring.thymeleaf.view-names
    指定使用模板的视图名,多个以逗号分隔.

mustcache

  • spring.mustache.cache
    是否Enable template caching.

  • spring.mustache.charset
    指定Template的编码.

  • spring.mustache.check-template-location
    是否检查默认的路径是否存在.

  • spring.mustache.content-type
    指定Content-Type.

  • spring.mustache.enabled
    是否开启mustcache的模板支持.

  • spring.mustache.prefix
    指定模板的前缀,默认: classpath:/templates/

  • spring.mustache.suffix
    指定模板的后缀,默认: .html

  • spring.mustache.view-names
    指定要使用模板的视图名.

groovy模板

  • spring.groovy.template.allow-request-override
    指定HttpServletRequest的属性是否可以覆盖controller的model的同名项

  • spring.groovy.template.allow-session-override
    指定HttpSession的属性是否可以覆盖controller的model的同名项

  • spring.groovy.template.cache
    是否开启模板缓存.

  • spring.groovy.template.charset
    指定Template编码.

  • spring.groovy.template.check-template-location
    是否检查模板的路径是否存在.

  • spring.groovy.template.configuration.auto-escape
    是否在渲染模板时自动排查model的变量,默认为: false

  • spring.groovy.template.configuration.auto-indent
    是否在渲染模板时自动缩进,默认为false

  • spring.groovy.template.configuration.auto-indent-string
    如果自动缩进启用的话,是使用SPACES还是TAB,默认为: SPACES

  • spring.groovy.template.configuration.auto-new-line
    渲染模板时是否要输出换行,默认为false

  • spring.groovy.template.configuration.base-template-class
    指定template base class.

  • spring.groovy.template.configuration.cache-templates
    是否要缓存模板,默认为true

  • spring.groovy.template.configuration.declaration-encoding
    在写入declaration header时使用的编码

  • spring.groovy.template.configuration.expand-empty-elements
    是使用<br/>这种形式,还是<br></br>这种展开模式,默认为: false)

  • spring.groovy.template.configuration.locale
    指定template locale.

  • spring.groovy.template.configuration.new-line-string
    当启用自动换行时,换行的输出,默认为系统的line.separator属性的值

  • spring.groovy.template.configuration.resource-loader-path
    指定groovy的模板路径,默认为classpath:/templates/

  • spring.groovy.template.configuration.use-double-quotes
    指定属性要使用双引号还是单引号,默认为false

  • spring.groovy.template.content-type
    指定Content-Type.

  • spring.groovy.template.enabled
    是否开启groovy模板的支持.

  • spring.groovy.template.expose-request-attributes
    设定所有request的属性在merge到模板的时候,是否要都添加到model中.

  • spring.groovy.template.expose-session-attributes
    设定所有request的属性在merge到模板的时候,是否要都添加到model中.

  • spring.groovy.template.expose-spring-macro-helpers
    设定是否以springMacroRequestContext的形式暴露RequestContext给Spring’s macro library使用

  • spring.groovy.template.prefix
    指定模板的前缀.

  • spring.groovy.template.request-context-attribute
    指定RequestContext属性的名.

  • spring.groovy.template.resource-loader-path
    指定模板的路径,默认为: classpath:/templates/

  • spring.groovy.template.suffix
    指定模板的后缀

  • spring.groovy.template.view-names
    指定要使用模板的视图名称.

http

  • spring.hateoas.apply-to-primary-object-mapper
    设定是否对object mapper也支持HATEOAS,默认为: true

  • spring.http.converters.preferred-json-mapper
    是否优先使用JSON mapper来转换.

  • spring.http.encoding.charset
    指定http请求和相应的Charset,默认: UTF-8

  • spring.http.encoding.enabled
    是否开启http的编码支持,默认为true

  • spring.http.encoding.force
    是否强制对http请求和响应进行编码,默认为true

json

  • spring.jackson.date-format
    指定日期格式,比如yyyy-MM-dd HH:mm:ss,或者具体的格式化类的全限定名

  • spring.jackson.deserialization
    是否开启Jackson的反序列化

  • spring.jackson.generator
    是否开启json的generators.

  • spring.jackson.joda-date-time-format
    指定Joda date/time的格式,比如yyyy-MM-dd HH:mm:ss). 如果没有配置的话,dateformat会作为backup

  • spring.jackson.locale
    指定json使用的Locale.

  • spring.jackson.mapper
    是否开启Jackson通用的特性.

  • spring.jackson.parser
    是否开启jackson的parser特性.

  • spring.jackson.property-naming-strategy
    指定PropertyNamingStrategy (CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES)或者指定PropertyNamingStrategy子类的全限定类名.

  • spring.jackson.serialization
    是否开启jackson的序列化.

  • spring.jackson.serialization-inclusion
    指定序列化时属性的inclusion方式,具体查看JsonInclude.Include枚举.

  • spring.jackson.time-zone
    指定日期格式化时区,比如America/Los_Angeles或者GMT+10.

jersey

  • spring.jersey.filter.order
    指定Jersey filter的order,默认为: 0

  • spring.jersey.init
    指定传递给Jersey的初始化参数.

  • spring.jersey.type
    指定Jersey的集成类型,可以是servlet或者filter.

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Wesley13 Wesley13
2年前
java常用类(2)
三、时间处理相关类Date类:计算机世界把1970年1月1号定为基准时间,每个度量单位是毫秒(1秒的千分之一),用long类型的变量表示时间。Date分配Date对象并初始化对象,以表示自从标准基准时间(称为“历元”(epoch),即1970年1月1日08:00:00GMT)以来的指定毫秒数。示例:packagecn.tanjian
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Wesley13 Wesley13
2年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
2年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Easter79 Easter79
2年前
Spring注解@Resource和@Autowired区别对比、spring扫描的默认bean的Id、程序获取spring容器对象
\注解扫面的bean的ID问题0.前提需要明白注解扫描出来的bean的id默认是类名首字母小写,当然可以指定id:
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这