真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

從SpringBoot1.5升級到2.0

POM

  • 1.5

    org.springframework.boot
    spring-boot-starter-parent
    1.5.10.RELEASE
    
  • 2.0

    org.springframework.boot
    spring-boot-starter-parent
    2.0.7.RELEASE
    

Spring Data

Spring Data的一些方法進(jìn)行了重命名:

創(chuàng)新互聯(lián)建站堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的舞陽網(wǎng)站設(shè)計(jì)、移動媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

  • findOne(id) -> findById(id) (返回的是Optional)
  • delete(id) -> deleteById(id)
  • exists(id) -> existsById(id)
  • findAll(ids) -> findAllById(ids)

配置

在升級時(shí),可以在pom中增加spring-boot-properties-migrator,這樣在啟動時(shí)會提示需要更改的配置:


    org.springframework.boot
    spring-boot-properties-migrator
    runtime

其中改動較大的是security(The security auto-configuration is no longer customizable,A global security auto-configuration is now provided)、management、banner、server等。

  • security

security開頭的配置及management.security均已過期,如以下的配置不再支持,需要調(diào)整到代碼中:

security:
  ignored: /api-docs,/swagger-resources/**,/swagger-ui.html**,/webjars/**
  • management
management:
  security:
    enabled: false
  port: 8090

修改為:

management:
  server:
    port: 8090
  • datasource
datasource:
    initialize: false

修改為:

datasource:
    initialization-mode: never

如使用PostgreSQL,可能會報(bào)錯:Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented hibernate,需修改配置:

jpa:
    database-platform: org.hibernate.dialect.PostgreSQLDialect
    properties:
       hibernate:
         default_schema: test
         jdbc:
           lob:
             non_contextual_creation: true
  • banner調(diào)整為spring.banner
  • server調(diào)整為server.servlet

更多需要調(diào)整的參數(shù)請看文末參考文檔。

Security

WebSecurityConfigurerAdapter

  • security.ignored
@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/api-docs", "/swagger-resources/**", "/swagger-ui.html**", "/webjars/**");
}
  • AuthenticationManager

如在代碼中注入了AuthenticationManager,

@Autowired
private AuthenticationManager authenticationManager;

在啟動時(shí)會報(bào)錯:Field authenticationManager required a bean of type 'org.springframework.security.authentication.AuthenticationManager' that could not be found.請?jiān)赪ebSecurityConfigurerAdapter中增加以下代碼:

@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

Actuator

  • 配置屬性變化
Old propertyNew property
endpoints.id.* management.endpoint.id.*
endpoints.cors.* management.endpoints.web.cors.*
endpoints.jmx.* management.endpoints.jmx.*
management.address management.server.address
management.context-path management.server.servlet.context-path
management.ssl.* management.server.ssl.*
management.port management.server.port

management.endpoints.web.base-path的默認(rèn)值為/actuator,即Actuator訪問路徑前部增加了actuator([/actuator/health],[/actuator/info]),這可以在啟動日志中看到。
因management.security不再支持,權(quán)限配置需添加到WebSecurityConfigurerAdapter中:

.authorizeRequests()
.requestMatchers(EndpointRequest.to("health", "info")).permitAll()
  • Endpoint變化
EndpointChanges
/actuator No longer available. There is, however, a mapping available at the root of management.endpoints.web.base-path that provides links to all the exposed endpoints.
/auditevents The after parameter is no longer required
/autoconfig Renamed to /conditions
/docs No longer available (the API documentation is part of the published documentation now)
/health Rather than relying on the sensitive flag to figure out if the health endpoint had to show full details or not, there is now a management.endpoint.health.show-details option: never, always, when-authorized. By default, /actuator/health is exposed and details are not shown.
/trace Renamed to /httptrace

新特性

  • Configuration Property Binding

可以在代碼中直接使用Binder API從配置文件中讀取內(nèi)容:

public class Person implements EnvironmentAware {
        private Environment environment;

        @Override
        public void setEnvironment(Environment environment) {
            this.environment = environment;
        }

        public void bind() {
            List people = Binder.get(environment)
            .bind("my.property", Bindable.listOf(PersonName.class))
            .orElseThrow(IllegalStateException::new);
        }
}

YAML配置

my:
  property:
  - first-name: Jane
    last-name: Doe
  - first-name: John
    last-name: Doe
  • Spring Data Web Configuration

新增spring.data.web配置來設(shè)置分頁和排序:

# DATA WEB (SpringDataWebProperties)
spring.data.web.pageable.default-page-size=20 # Default page size.
spring.data.web.pageable.max-page-size=2000 # Maximum page size to be accepted.
spring.data.web.pageable.one-indexed-parameters=false # Whether to expose and assume 1-based page number indexes.
spring.data.web.pageable.page-parameter=page # Page index parameter name.
spring.data.web.pageable.prefix= # General prefix to be prepended to the page number and page size parameters.
spring.data.web.pageable.qualifier-delimiter=_ # Delimiter to be used between the qualifier and the actual page number and size properties.
spring.data.web.pageable.size-parameter=size # Page size parameter name.
spring.data.web.sort.sort-parameter=sort # Sort parameter name.
  • 支持自定義JdbcTemplate
# JDBC (JdbcProperties)
spring.jdbc.template.fetch-size=-1 # Number of rows that should be fetched from the database when more rows are needed.
spring.jdbc.template.max-rows=-1 # Maximum number of rows.
spring.jdbc.template.query-timeout= # Query timeout. Default is to use the JDBC driver's default configuration. If a duration suffix is not specified, seconds will be used.
  • 支持hibernate自定義命名策略
  • Reactive

更多新特性請查看Release Notes。

Swagger


    io.springfox
    springfox-swagger2
    2.9.2


    io.springfox
    springfox-swagger-ui
    2.9.2

Swagger 2.9版本,增加了對@ApiParam屬性example的處理,在Swagger UI和文檔中會顯示,因此要注意設(shè)置合適的example值:

@ApiOperation(value = "Delete airline by id")
@GetMapping("/airlines/delete/{airlineId}")
public void deleteAirline(@ApiParam(required = true, example = "123") @PathVariable Long airlineId)

否則你會看到Warn日志:
AbstractSerializableParameter

@JsonProperty("x-example")
public Object getExample() {
    if (example == null) {
        return null;
    }
    try {
        if (BaseIntegerProperty.TYPE.equals(type)) {
            return Long.valueOf(example);
        } else if (DecimalProperty.TYPE.equals(type)) {
            return Double.valueOf(example);
        } else if (BooleanProperty.TYPE.equals(type)) {
            if ("true".equalsIgnoreCase(example) || "false".equalsIgnoreCase(defaultValue)) {
                return Boolean.valueOf(example);
            }
        }
    } catch (NumberFormatException e) {
        LOGGER.warn(String.format("Illegal DefaultValue %s for parameter type %s", defaultValue, type), e);
    }
    return example;
}

另外Swagger 2.9.2會為org.springframework.data.domain.Pageable自動增加@ApiImplicitParams。

參考文檔

Spring Boot Reference Guide 2.0.7.RELEASE
Spring Boot 2.0 Migration Guide
Spring Boot 2.0 Configuration Changelog
Spring Boot 2.0 Release Notes
Spring Boot Relaxed Binding 2.0


網(wǎng)頁名稱:從SpringBoot1.5升級到2.0
URL分享:http://weahome.cn/article/jseogj.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部