GVKun编程网logo

SpringBoot 使用 WEB 进阶(springboot webjars)

40

对于SpringBoot使用WEB进阶感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍springbootwebjars,并为您提供关于idea:springinitializr无web勾选,m

对于SpringBoot 使用 WEB 进阶感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍springboot webjars,并为您提供关于idea:spring initializr 无 web 勾选,maven 方式搭建 springboot 项目。jdk7 创建 springboot 项目的版本不兼容问题。、java-study-springboot-基础学习-05-springboot web开发、springboot jdk11 spring-boot-starter-webflux 启动报错、springboot 之web进阶的有用信息。

本文目录一览:

SpringBoot 使用 WEB 进阶(springboot webjars)

SpringBoot 使用 WEB 进阶(springboot webjars)

1. 使用 aop 处理请求 get,post

2. 统一异常检查

3. 单元测试

4 效果预览:

 

5. 开发环境

    maven 开发环境:3.3.9

    Itellij IDEA 旗舰版

    java 开发环境 java version "1.8.0_91"

6. 完成的 完整的代码实例

HttpAspect

package com.hls;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class HlsApplication {

	public static void main(String[] args) {
		SpringApplication.run(HlsApplication.class, args);
	}
}

 

BoyController


package com.hls.controller;

import com.hls.domain.Boy;
import com.hls.domain.Result;
import com.hls.repository.BoyRepository;
import com.hls.service.BoyService;
import com.hls.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * Created by huangliusong on 2017/7/19.
 * 查询男生列表
 */
@RestController
public class BoyController {
    @Autowired
    private BoyRepository boyRepository;
    @Autowired
    private BoyService boyService;
    @GetMapping(value = "/boys")
    public List<Boy> boylist(){
        return boyRepository.findAll();
    }

    @PostMapping(value="/boys")
    public Result<Boy>  boyadd(@Valid Boy boy, BindingResult bindingResult){
        if(bindingResult.hasErrors()){

            return ResultUtil.error(0,bindingResult.getFieldError().getDefaultMessage());
        }
        boy.setAge(boy.getAge());
        boy.setBirth(boy.getBirth());
        boy.setId(1001);
        return ResultUtil.success(boyRepository.save(boy));
    }

    //查询
    @GetMapping(value = "/boys/{id}")
    public Boy findBoy(@PathVariable("id")Integer id){
        return boyRepository.findOne(id);
    }
    //更新
    @PostMapping(value = "/boys/{id}")
    public Boy updateBoy(@PathVariable("id")Integer id,
                         @RequestParam("age")String age,
                         @RequestParam("birth")String birth){
        Boy boy=new Boy();
        boy.setId(id);
        boy.setBirth(birth);
        boy.setAge(age);
        return boyRepository.save(boy);
    }
    //删除
    @DeleteMapping(value = "/boys/{id}")
    public void deleteBoy(@PathVariable("id")Integer id){
        boyRepository.delete(id);
    }

    //通过年龄查询
    @GetMapping(value = "boys/age/{age}")
    public List<Boy> boylistByAge(@PathVariable("age") String age){
        return boyRepository.findByAge(age);
    }

    @PostMapping(value = "/boys/two")
    public void boyTwo(){
        boyService.insertBoyTow();
    }

    /**
     * 对年龄进行判断
     */
    @GetMapping(value = "/boys/getAge/{id}")
    public void  getAge(@PathVariable("id")Integer id)throws Exception{
        boyService.getAge(id);
    }
}


HelloController

package com.hls.controller;

import com.hls.repository.Boyproperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by huangliusong on 2017/7/18.
 */
@RestController
@RequestMapping("/huang")
public class HelloController {

    @Autowired
    private Boyproperties boyproperties;
    @GetMapping("/liu1")
    public String say  (@RequestParam(value="id",required = false, defaultValue ="0") Integer id){
        return "index.html?"+id;
    }
}

Boy

package com.hls.domain;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.validation.constraints.Min;

/**
 * Created by huangliusong on 2017/7/19.
 */
@Entity
public class Boy {
    @Id
    @GeneratedValue
    private Integer id;
    @Min(value=18,message = "不是18,不能录入进去")
    private String age;
    private String birth;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getBirth() {
        return birth;
    }

    public void setBirth(String birth) {
        this.birth = birth;
    }

    public Boy() {
    }

    @Override
    public String toString() {
        return "Boy{" +
                "id=" + id +
                ", age=''" + age + ''\'''' +
                ", birth=''" + birth + ''\'''' +
                ''}'';
    }
}


Result

package com.hls.domain;

/**
 * http请求返回的最外层对象
 * Created by huangliusong on 2017/7/22.
 */
public class Result<T> {
    //错误码
    private Integer code;
    //提示信息
    private  String msg;
    //具体的内容
    private T data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}

ResultEnum

package com.hls.enmus;

/**
 * Created by huangliusong on 2017/7/22.
 */
public enum ResultEnum {
    UNKNOW_ERROR(-1,"未知错误"),
    SUCCESS(0,"成功"),
    PRIMARY_SCHOOL(1001,"你还在上小学"),
    MIDDLE_SCHOOL(1002,"你还在上初中")

            ;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    private Integer code;
    private String msg;

    ResultEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }
}

BoyException

package com.hls.exception;

import com.hls.domain.Result;
import com.hls.enmus.ResultEnum;

/**
 * Created by huangliusong on 2017/7/22.
 */
public class BoyException extends RuntimeException{
    private   Integer code;

    public BoyException(ResultEnum resultEnum) {
        super(resultEnum.getMsg());
        this.code = resultEnum.getCode();
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
}

ExceptionHandle

package com.hls.handler;

import com.hls.domain.Result;
import com.hls.exception.BoyException;
import com.hls.util.ResultUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by huangliusong on 2017/7/22.
 */
@ControllerAdvice
public class ExceptionHandle {
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handler(Exception e){
        if(e instanceof BoyException){
            BoyException boyException=(BoyException)e;
            return ResultUtil.error(boyException.getCode(),boyException.getMessage());
        }else{
            return ResultUtil.error(-1,"未知错误");
        }

    }
}

Boyproperties

package com.hls.repository;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * Created by huangliusong on 2017/7/18.
 */
@Component
@ConfigurationProperties(prefix = "boy")
public class Boyproperties {
    private String hlsBirth;
    private Integer hlsAge;
    public String getHlsBirth() {
        return hlsBirth;
    }

    public void setHlsBirth(String hlsBirth) {
        this.hlsBirth = hlsBirth;
    }

    public void setHlsAge(Integer hlsAge) {
        this.hlsAge = hlsAge;
    }

    public Integer getHlsAge() {
        return hlsAge;
    }


}


BoyRepository

package com.hls.repository;

import com.hls.domain.Boy;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

/**
 * Created by huangliusong on 2017/7/19.
 */
public interface BoyRepository extends JpaRepository<Boy,Integer>{
    //通过年龄查询
    public List<Boy> findByAge(String age);
}

    BoyService

package com.hls.service;

import com.hls.enmus.ResultEnum;
import com.hls.exception.BoyException;
import com.hls.repository.BoyRepository;
import com.hls.domain.Boy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * Created by huangliusong on 2017/7/21.
 */
@Service
public class BoyService {
    @Autowired
    private BoyRepository boyRepository;
    //添加事物注解
    @Transactional
    public void insertBoyTow(){
        Boy boy1=new Boy();
        boy1.setAge("67");
        boy1.setBirth("1967");
        Boy boy2=new Boy();
        boy2.setAge("688");
        boy2.setBirth("1968");

        boyRepository.save(boy1);
        boyRepository.save(boy2);
    }
    public void getAge(Integer id) throws  Exception{
        Boy boy=boyRepository.findOne(id);
        Integer age=Integer.parseInt(boy.getAge());
        System.out.println(age);
        if(age<10){
            //返回你还在上小学
            throw new BoyException(ResultEnum.PRIMARY_SCHOOL);
        }else if(age>10&&age<16){
            //返回 你还在上初中
            throw new BoyException(ResultEnum.MIDDLE_SCHOOL);
        }

    }

    /**
     * 通过id查询详细信息
     * @param id
     * @return
     */
    public Boy findOneBoy(Integer id){
        return boyRepository.findOne(id);
    }
}

ResultUtil

package com.hls.util;

import com.hls.domain.Result;
import com.sun.org.apache.regexp.internal.RE;

/**
 * Created by huangliusong on 2017/7/22.
 */
public class ResultUtil {
    public static Result success(Object object){
        Result result=new Result();
        result.setCode(0);
        result.setData(object);
        result.setMsg("成功");
        return result;
    }
    public  static Result success(){
        return success(null);
    }
    public static Result error(Integer code,String msg){
        Result result=new Result();
        result.setMsg(msg);
        result.setCode(code);
        result.setData("null");
        return result;
    }
}

HlsApplication

package com.hls;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class HlsApplication {

	public static void main(String[] args) {
		SpringApplication.run(HlsApplication.class, args);
	}
}

 

idea:spring initializr 无 web 勾选,maven 方式搭建 springboot 项目。jdk7 创建 springboot 项目的版本不兼容问题。

idea:spring initializr 无 web 勾选,maven 方式搭建 springboot 项目。jdk7 创建 springboot 项目的版本不兼容问题。

一、idea 使用 spring initializr 不选择 web 搭建 springboot 项目

1.file => new => project

 

 

2. 直接 next 到 finish 结束。

 

 

3. 完成后创建 controller 用例测试

 

4.pom 文件

 

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>cc.ash</groupId>
    <artifactId>boot-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>boot-demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!--  手动添加web依赖,@restController @requestMapping注解等      -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

 

5.application.properties

#端口号修改。默认8080
server.port=

 

6.springboot 入口启动类

package cc.ash.bootdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@SpringBootApplication
@Controller
public class BootDemoApplication {


    @RequestMapping("/boot")
    @ResponseBody
    public String bootTest() {

        return "hello springboot";
    }
    public static void main(String[] args) {
        SpringApplication.run(BootDemoApplication.class, args);
    }

}

 

7. 新建包下 controller 测试类

package cc.ash.bootdemo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @RequestMapping(name="springboot test", value = "/test")
    public String test() {
        return "booted";
    }
}

 

 

8. 运行结果

新建包下 controller 测试类:访问页面

 

springboot 启动类中访问 404。改 requestMapping、rerun,做了很多操作到怀疑人生。重启 idea,世界终于正常了。

 

能正常访问的结果如下

 

 

二、maven 搭建 springboot 项目

 

1.jdk7 的情况下

2.maven 搭建

 

 

创建完成后的项目结构和 pom 文件。一个字就是干净

 

3. 手动添加 pom 依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>


<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>


<groupId>cc.ash</groupId>
<artifactId>boot-demo</artifactId>
<version>1.0-SNAPSHOT</version>


<properties>
<java.version>1.8</java.version>
</properties>

<!-- =================jdk1.7与springboot版本不兼容======================= -->
<!--<properties>
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.myproject.Application</start-class>
</properties>-->

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<!-- 手动添加web依赖,@restController @requestMapping注解等 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

 

 

maven 导入依赖(未选择自动导入的情况下)。

 

4. 编写测试用例代码

1). 测试 controller:

  TestController

package cc.ash.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @RequestMapping(name="maven手动创建springboot",value={"/manual", "mvnManual"})
    @ResponseBody
    public String test() {

        return "maven manual";
    }

}

 

2. 启动入口:

DemoApplication
package cc.ash;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

 

 

3. 完成后代码结构

 

5. 访问测试

 

6.jdk1.7 错误留存

不兼容问题

https://blog.csdn.net/wj197927/article/details/79557017

https://www.jianshu.com/p/95d8a0cf0244

 

idea 日志记录(非控制台日志,控制台日志如上)

 7.springboot 项目结构导致 controller 访问 404 的问题

自建的所有需要扫描注解的类,必须与启动类的包平级或者在其之下。如启动类在包【aa.bb】,其他需要扫描的类必须在【aa.bb】中或【aa.bb】之下的包里。

参考链接:

详细说明的:https://www.cnblogs.com/remember-me/p/10091126.html

直接上解决方法的:https://blog.csdn.net/dong__CSDN/article/details/85342180

 

java-study-springboot-基础学习-05-springboot web开发

java-study-springboot-基础学习-05-springboot web开发

SpringBoot 之web开发

1、自动配置类说明

Web开发的自动配置类: org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration
clipboard.png

clipboard.png
比如:
spring mvc的前后缀配置

clipboard.png
在WebMvcAutoConfiguration中对应方法
clipboard.png
对应配置文件
clipboard.png

2、静态资源配置说明

如果进入SpringMVC的规则为/时,SpringBoot的默认静态资源的路径为:
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
如果某个静态文件不在上面的配置路径中,那么从浏览器中就访问不到了

3、自定义消息转化器

  • 原有的spring mvc 配置

clipboard.png

  • springboot 配置

clipboard.png

4、自定义拦截器

  • 继承org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter

参考:https://github.com/chengbingh...

springboot jdk11 spring-boot-starter-webflux 启动报错

springboot jdk11 spring-boot-starter-webflux 启动报错

2019-11-22 15:14:28.112 DEBUG 11988 --- [           main] .c.l.ClasspathLoggingApplicationListener : Application started with classpath: unknown

  .   ____          _            __ _ _
 /\\ / ___''_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | ''_ | ''_| | ''_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  ''  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.1.RELEASE)

2019-11-22 15:14:28.272  INFO 11988 --- [           main] com.weir.r2dbc.R2dbcDemoApplication      : Starting R2dbcDemoApplication on DEEP-2019KDGHCG with PID 11988 (E:\weir-project2\r2dbc-demo\target\classes started by Administrator in E:\weir-project2\r2dbc-demo)
2019-11-22 15:14:28.273 DEBUG 11988 --- [           main] com.weir.r2dbc.R2dbcDemoApplication      : Running with Spring Boot v2.2.1.RELEASE, Spring v5.2.1.RELEASE
2019-11-22 15:14:28.274  INFO 11988 --- [           main] com.weir.r2dbc.R2dbcDemoApplication      : No active profile set, falling back to default profiles: default
2019-11-22 15:14:28.275 DEBUG 11988 --- [           main] o.s.boot.SpringApplication               : Loading source class com.weir.r2dbc.R2dbcDemoApplication
2019-11-22 15:14:28.351 DEBUG 11988 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Loaded config file ''file:/E:/weir-project2/r2dbc-demo/target/classes/application.properties'' (classpath:/application.properties)
2019-11-22 15:14:28.352 DEBUG 11988 --- [           main] onfigReactiveWebServerApplicationContext : Refreshing org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@65b104b9
2019-11-22 15:14:28.377 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.context.annotation.internalConfigurationAnnotationProcessor''
2019-11-22 15:14:28.399 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory''
2019-11-22 15:14:28.509 DEBUG 11988 --- [           main] o.s.c.a.ClassPathBeanDefinitionScanner   : Identified candidate component class: file [E:\weir-project2\r2dbc-demo\target\classes\com\weir\r2dbc\OrdersController.class]
2019-11-22 15:14:28.815 DEBUG 11988 --- [           main] o.s.c.e.PropertySourcesPropertyResolver  : Found key ''spring.r2dbc.url'' in PropertySource ''configurationProperties'' with value of type String
2019-11-22 15:14:28.820 DEBUG 11988 --- [           main] o.s.c.e.PropertySourcesPropertyResolver  : Found key ''spring.r2dbc.url'' in PropertySource ''configurationProperties'' with value of type String
2019-11-22 15:14:28.827 DEBUG 11988 --- [           main] o.s.c.e.PropertySourcesPropertyResolver  : Found key ''spring.r2dbc.url'' in PropertySource ''configurationProperties'' with value of type String
2019-11-22 15:14:29.033 DEBUG 11988 --- [           main] o.s.c.e.PropertySourcesPropertyResolver  : Found key ''spring.r2dbc.url'' in PropertySource ''configurationProperties'' with value of type String
2019-11-22 15:14:29.037 DEBUG 11988 --- [           main] o.s.c.e.PropertySourcesPropertyResolver  : Found key ''spring.r2dbc.url'' in PropertySource ''configurationProperties'' with value of type String
2019-11-22 15:14:29.079  INFO 11988 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-11-22 15:14:29.088 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.autoconfigure.AutoConfigurationPackages''
2019-11-22 15:14:29.099 DEBUG 11988 --- [           main] o.s.b.a.AutoConfigurationPackages        : @EnableAutoConfiguration was declared on a class in the package ''com.weir.r2dbc''. Automatic @Repository and @Entity scanning is enabled.
2019-11-22 15:14:29.102 DEBUG 11988 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Scanning for repositories in packages com.weir.r2dbc.
2019-11-22 15:14:29.113 DEBUG 11988 --- [           main] o.s.d.r.c.RepositoryComponentProvider    : Identified candidate component class: file [E:\weir-project2\r2dbc-demo\target\classes\com\weir\r2dbc\OrdersRepository.class]
2019-11-22 15:14:29.338  INFO 11988 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 235ms. Found 1 repository interfaces.
2019-11-22 15:14:29.569 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''propertySourcesPlaceholderConfigurer''
2019-11-22 15:14:29.575 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator''
2019-11-22 15:14:29.643 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.context.event.internalEventListenerProcessor''
2019-11-22 15:14:29.646 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.context.event.internalEventListenerFactory''
2019-11-22 15:14:29.646 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.transaction.config.internalTransactionalEventListenerFactory''
2019-11-22 15:14:29.652 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.context.annotation.internalAutowiredAnnotationProcessor''
2019-11-22 15:14:29.653 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.context.annotation.internalCommonAnnotationProcessor''
2019-11-22 15:14:29.657 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor''
2019-11-22 15:14:29.658 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.context.internalConfigurationPropertiesBinder''
2019-11-22 15:14:29.658 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.context.internalConfigurationPropertiesBinderFactory''
2019-11-22 15:14:29.661 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''methodValidationPostProcessor''
2019-11-22 15:14:29.698 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''methodValidationPostProcessor'' via factory method to bean named ''environment''
2019-11-22 15:14:29.715 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''persistenceExceptionTranslationPostProcessor''
2019-11-22 15:14:29.716 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''persistenceExceptionTranslationPostProcessor'' via factory method to bean named ''environment''
2019-11-22 15:14:29.722 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''connectionFactoryInitializerPostProcessor''
2019-11-22 15:14:29.725 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''connectionFactoryInitializerPostProcessor'' via constructor to bean named ''org.springframework.beans.factory.support.DefaultListableBeanFactory@58fb7731''
2019-11-22 15:14:29.727 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.aop.config.internalAutoProxyCreator''
2019-11-22 15:14:29.756 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''webServerFactoryCustomizerBeanPostProcessor''
2019-11-22 15:14:29.761 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''nettyReactiveWebServerFactory''
2019-11-22 15:14:29.762 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryConfiguration$EmbeddedNetty''
2019-11-22 15:14:29.765 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.transaction.config.internalTransactionAdvisor''
2019-11-22 15:14:29.765 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration''
2019-11-22 15:14:29.781 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''transactionAttributeSource''
2019-11-22 15:14:29.788 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''transactionInterceptor''
2019-11-22 15:14:29.789 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''transactionInterceptor'' via factory method to bean named ''transactionAttributeSource''
2019-11-22 15:14:29.827 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''org.springframework.transaction.config.internalTransactionAdvisor'' via factory method to bean named ''transactionAttributeSource''
2019-11-22 15:14:29.827 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''org.springframework.transaction.config.internalTransactionAdvisor'' via factory method to bean named ''transactionInterceptor''
2019-11-22 15:14:29.836 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''reactorServerResourceFactory''
2019-11-22 15:14:29.845 DEBUG 11988 --- [           main] reactor.util.Loggers$LoggerFactory       : Using Slf4j logging framework
2019-11-22 15:14:29.878 DEBUG 11988 --- [           main] i.n.u.i.logging.InternalLoggerFactory    : Using SLF4J as the default logging framework
2019-11-22 15:14:29.880 DEBUG 11988 --- [           main] i.netty.util.internal.PlatformDependent  : Platform: Windows
2019-11-22 15:14:29.882 DEBUG 11988 --- [           main] i.n.util.internal.PlatformDependent0     : -Dio.netty.noUnsafe: false
2019-11-22 15:14:29.882 DEBUG 11988 --- [           main] i.n.util.internal.PlatformDependent0     : Java version: 11
2019-11-22 15:14:29.884 DEBUG 11988 --- [           main] i.n.util.internal.PlatformDependent0     : sun.misc.Unsafe.theUnsafe: available
2019-11-22 15:14:29.886 DEBUG 11988 --- [           main] i.n.util.internal.PlatformDependent0     : sun.misc.Unsafe.copyMemory: available
2019-11-22 15:14:29.887 DEBUG 11988 --- [           main] i.n.util.internal.PlatformDependent0     : java.nio.Buffer.address: available
2019-11-22 15:14:29.890 DEBUG 11988 --- [           main] i.n.util.internal.PlatformDependent0     : direct buffer constructor: unavailable

java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled
    at io.netty.util.internal.ReflectionUtil.trySetAccessible(ReflectionUtil.java:31)
    at io.netty.util.internal.PlatformDependent0$4.run(PlatformDependent0.java:225)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:219)
    at io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:273)
    at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:92)
    at io.netty.util.ConstantPool.<init>(ConstantPool.java:32)
    at io.netty.util.AttributeKey$1.<init>(AttributeKey.java:27)
    at io.netty.util.AttributeKey.<clinit>(AttributeKey.java:27)
    at reactor.netty.resources.PooledConnectionProvider.<clinit>(PooledConnectionProvider.java:215)
    at reactor.netty.resources.ConnectionProvider.fixed(ConnectionProvider.java:188)
    at reactor.netty.resources.ConnectionProvider.fixed(ConnectionProvider.java:159)
    at reactor.netty.resources.ConnectionProvider.fixed(ConnectionProvider.java:141)
    at reactor.netty.tcp.TcpResources.create(TcpResources.java:291)
    at reactor.netty.tcp.TcpResources.getOrCreate(TcpResources.java:236)
    at reactor.netty.http.HttpResources.get(HttpResources.java:41)
    at org.springframework.http.client.reactive.ReactorResourceFactory.afterPropertiesSet(ReactorResourceFactory.java:162)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1862)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1287)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:874)
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:778)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:528)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.getWebServerFactory(ReactiveWebServerApplicationContext.java:111)
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.createWebServer(ReactiveWebServerApplicationContext.java:89)
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:78)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
    at com.weir.r2dbc.R2dbcDemoApplication.main(R2dbcDemoApplication.java:20)

2019-11-22 15:14:29.901 DEBUG 11988 --- [           main] i.n.util.internal.PlatformDependent0     : java.nio.Bits.unaligned: available, true
2019-11-22 15:14:29.903 DEBUG 11988 --- [           main] i.n.util.internal.PlatformDependent0     : jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable

java.lang.IllegalAccessException: class io.netty.util.internal.PlatformDependent0$6 cannot access class jdk.internal.misc.Unsafe (in module java.base) because module java.base does not export jdk.internal.misc to unnamed module @2c768ada
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591)
    at java.base/java.lang.reflect.Method.invoke(Method.java:558)
    at io.netty.util.internal.PlatformDependent0$6.run(PlatformDependent0.java:335)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:326)
    at io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:273)
    at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:92)
    at io.netty.util.ConstantPool.<init>(ConstantPool.java:32)
    at io.netty.util.AttributeKey$1.<init>(AttributeKey.java:27)
    at io.netty.util.AttributeKey.<clinit>(AttributeKey.java:27)
    at reactor.netty.resources.PooledConnectionProvider.<clinit>(PooledConnectionProvider.java:215)
    at reactor.netty.resources.ConnectionProvider.fixed(ConnectionProvider.java:188)
    at reactor.netty.resources.ConnectionProvider.fixed(ConnectionProvider.java:159)
    at reactor.netty.resources.ConnectionProvider.fixed(ConnectionProvider.java:141)
    at reactor.netty.tcp.TcpResources.create(TcpResources.java:291)
    at reactor.netty.tcp.TcpResources.getOrCreate(TcpResources.java:236)
    at reactor.netty.http.HttpResources.get(HttpResources.java:41)
    at org.springframework.http.client.reactive.ReactorResourceFactory.afterPropertiesSet(ReactorResourceFactory.java:162)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1862)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1287)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:874)
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:778)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:528)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.getWebServerFactory(ReactiveWebServerApplicationContext.java:111)
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.createWebServer(ReactiveWebServerApplicationContext.java:89)
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:78)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
    at com.weir.r2dbc.R2dbcDemoApplication.main(R2dbcDemoApplication.java:20)

2019-11-22 15:14:29.904 DEBUG 11988 --- [           main] i.n.util.internal.PlatformDependent0     : java.nio.DirectByteBuffer.<init>(long, int): unavailable
2019-11-22 15:14:29.904 DEBUG 11988 --- [           main] i.netty.util.internal.PlatformDependent  : sun.misc.Unsafe: available
2019-11-22 15:14:29.906 DEBUG 11988 --- [           main] i.netty.util.internal.PlatformDependent  : maxDirectMemory: 8547991552 bytes (maybe)
2019-11-22 15:14:29.907 DEBUG 11988 --- [           main] i.netty.util.internal.PlatformDependent  : -Dio.netty.tmpdir: C:\Users\ADMINI~1\AppData\Local\Temp (java.io.tmpdir)
2019-11-22 15:14:29.908 DEBUG 11988 --- [           main] i.netty.util.internal.PlatformDependent  : -Dio.netty.bitMode: 64 (sun.arch.data.model)
2019-11-22 15:14:29.910 DEBUG 11988 --- [           main] i.netty.util.internal.PlatformDependent  : -Dio.netty.maxDirectMemory: -1 bytes
2019-11-22 15:14:29.910 DEBUG 11988 --- [           main] i.netty.util.internal.PlatformDependent  : -Dio.netty.uninitializedArrayAllocationThreshold: -1
2019-11-22 15:14:29.912 DEBUG 11988 --- [           main] io.netty.util.internal.CleanerJava9      : java.nio.ByteBuffer.cleaner(): available
2019-11-22 15:14:29.912 DEBUG 11988 --- [           main] i.netty.util.internal.PlatformDependent  : -Dio.netty.noPreferDirect: false
2019-11-22 15:14:29.919 DEBUG 11988 --- [           main] reactor.netty.tcp.TcpResources           : [http] resources will use the default LoopResources: DefaultLoopResources {prefix=reactor-http, daemon=true, selectCount=8, workerCount=8}
2019-11-22 15:14:29.919 DEBUG 11988 --- [           main] reactor.netty.tcp.TcpResources           : [http] resources will use the default ConnectionProvider: PooledConnectionProvider {name=http, poolFactory=reactor.netty.resources.ConnectionProvider$$Lambda$386/0x0000000800448c40@367b22e5}
2019-11-22 15:14:29.922 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''nettyReactiveWebServerFactory'' via factory method to bean named ''reactorServerResourceFactory''
2019-11-22 15:14:29.936 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''reactiveWebServerFactoryCustomizer''
2019-11-22 15:14:29.936 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryAutoConfiguration''
2019-11-22 15:14:29.938 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''server-org.springframework.boot.autoconfigure.web.ServerProperties''
2019-11-22 15:14:29.969 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''reactiveWebServerFactoryCustomizer'' via factory method to bean named ''server-org.springframework.boot.autoconfigure.web.ServerProperties''
2019-11-22 15:14:29.971 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''nettyWebServerFactoryCustomizer''
2019-11-22 15:14:29.972 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration$NettyWebServerFactoryCustomizerConfiguration''
2019-11-22 15:14:29.974 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''nettyWebServerFactoryCustomizer'' via factory method to bean named ''environment''
2019-11-22 15:14:29.974 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''nettyWebServerFactoryCustomizer'' via factory method to bean named ''server-org.springframework.boot.autoconfigure.web.ServerProperties''
2019-11-22 15:14:30.036 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''r2dbcDemoApplication''
2019-11-22 15:14:30.039 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''ordersController''
2019-11-22 15:14:30.046 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''ordersRepository''
2019-11-22 15:14:30.092 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''databaseClient''
2019-11-22 15:14:30.092 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.autoconfigure.data.r2dbc.R2dbcDataAutoConfiguration''
2019-11-22 15:14:30.095 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''connectionFactory''
2019-11-22 15:14:30.095 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryConfiguration$ConnectionPoolConnectionFactoryConfiguration''
2019-11-22 15:14:30.101 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''spring.r2dbc-org.springframework.boot.autoconfigure.r2dbc.R2dbcProperties''
2019-11-22 15:14:30.118 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''connectionFactory'' via factory method to bean named ''spring.r2dbc-org.springframework.boot.autoconfigure.r2dbc.R2dbcProperties''
2019-11-22 15:14:30.271 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''org.springframework.boot.autoconfigure.data.r2dbc.R2dbcDataAutoConfiguration'' via constructor to bean named ''connectionFactory''
2019-11-22 15:14:30.274 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''reactiveDataAccessStrategy''
2019-11-22 15:14:30.275 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''r2dbcMappingContext''
2019-11-22 15:14:30.277 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''r2dbcCustomConversions''
2019-11-22 15:14:30.342 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''r2dbcMappingContext'' via factory method to bean named ''r2dbcCustomConversions''
2019-11-22 15:14:30.359 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''reactiveDataAccessStrategy'' via factory method to bean named ''r2dbcMappingContext''
2019-11-22 15:14:30.359 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''reactiveDataAccessStrategy'' via factory method to bean named ''r2dbcCustomConversions''
2019-11-22 15:14:30.392 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''exceptionTranslator''
2019-11-22 15:14:30.413 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''databaseClient'' via factory method to bean named ''reactiveDataAccessStrategy''
2019-11-22 15:14:30.413 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''databaseClient'' via factory method to bean named ''exceptionTranslator''
2019-11-22 15:14:30.508 DEBUG 11988 --- [           main] o.s.d.r.c.s.RepositoryFactorySupport     : Initializing repository instance for com.weir.r2dbc.OrdersRepository…
2019-11-22 15:14:30.553 DEBUG 11988 --- [           main] o.s.d.r.c.s.RepositoryFactorySupport     : Finished creation of repository instance for com.weir.r2dbc.OrdersRepository.
2019-11-22 15:14:30.561 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration''
2019-11-22 15:14:30.562 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata''
2019-11-22 15:14:30.563 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration''
2019-11-22 15:14:30.563 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''standardJacksonObjectMapperBuilderCustomizer''
2019-11-22 15:14:30.565 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties''
2019-11-22 15:14:30.571 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''standardJacksonObjectMapperBuilderCustomizer'' via factory method to bean named ''org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@65b104b9''
2019-11-22 15:14:30.572 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''standardJacksonObjectMapperBuilderCustomizer'' via factory method to bean named ''spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties''
2019-11-22 15:14:30.573 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration''
2019-11-22 15:14:30.574 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$ParameterNamesModuleConfiguration''
2019-11-22 15:14:30.574 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''parameterNamesModule''
2019-11-22 15:14:30.578 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration''
2019-11-22 15:14:30.579 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''jacksonObjectMapper''
2019-11-22 15:14:30.582 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''jacksonObjectMapperBuilder'' via factory method to bean named ''org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@65b104b9''
2019-11-22 15:14:30.582 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''jacksonObjectMapperBuilder'' via factory method to bean named ''standardJacksonObjectMapperBuilderCustomizer''
2019-11-22 15:14:30.585 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''jsonComponentModule''
2019-11-22 15:14:30.585 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration''
2019-11-22 15:14:30.599 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''jacksonObjectMapper'' via factory method to bean named ''jacksonObjectMapperBuilder''
2019-11-22 15:14:30.633 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration$DefaultCodecsConfiguration''
2019-11-22 15:14:30.635 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''defaultCodecCustomizer''
2019-11-22 15:14:30.637 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''spring.http-org.springframework.boot.autoconfigure.http.HttpProperties''
2019-11-22 15:14:30.640 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''spring.codec-org.springframework.boot.autoconfigure.codec.CodecProperties''
2019-11-22 15:14:30.642 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''defaultCodecCustomizer'' via factory method to bean named ''spring.http-org.springframework.boot.autoconfigure.http.HttpProperties''
2019-11-22 15:14:30.642 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name ''defaultCodecCustomizer'' via factory method to bean named ''spring.codec-org.springframework.boot.autoconfigure.codec.CodecProperties''
2019-11-22 15:14:30.644 DEBUG 11988 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean ''org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration$JacksonCodecConfiguration''

springboot 之web进阶

springboot 之web进阶

@Entity //jsr303验证
public class Girl {
    @Id//主键
    @GeneratedValue //自增
    private Integer id;
    private String cupSize;
    @Min(value = 18,message = "未成年少女进制入内")
    private Integer age;

    //必须要有一个无参构造方法
    public Girl() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCupSize() {
        return cupSize;
    }

    public void setCupSize(String cupSize) {
        this.cupSize = cupSize;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}
@PostMapping(value="/girls")
public Girl girlAdd(@Valid Girl girl, BindingResult bindingResult){

    if (bindingResult.hasErrors()){
        System.out.println(bindingResult.getFieldError().getDefaultMessage());
        return null;
    }

    girl.setCupSize(girl.getCupSize());
    girl.setAge(girl.getAge());

    return girlRepository.save(girl);
}

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-aop</artifactId>
</dependency>

方式一:

@Aspect
@Component
public class HttpAspect {

    @Before("execution(public * com.imooc.girl.controller.GirlController.*(..))")
    public void log(){
        System.out.println("1111111111");
    }

    @After("execution(public * com.imooc.girl.controller.GirlController.*(..))")
    public void doAfter(){
        System.out.println("222222222");
    }

}

优化后:

@Aspect
@Component
public class HttpAspect {

    @Pointcut("execution(public * com.imooc.girl.controller.GirlController.*(..))")
    public void log(){

    }
    
    @Before("log()")
    public void doBefore(){
        System.out.println("1111111111");
    }

    @After("log()")
    public void doAfter(){
        System.out.println("222222222");
    }

}

在优化:

@Aspect
@Component
public class HttpAspect {

    private final static Logger logger = LoggerFactory.getLogger(HttpAspect.class);

    @Pointcut("execution(public * com.imooc.girl.controller.GirlController.*(..))")
    public void log(){

    }

    @Before("log()")
    public void doBefore(JoinPoint joinPoint){
        logger.info("1111111111");
        ServletRequestAttributes attributes=(ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        HttpServletRequest request=attributes.getRequest();
        //url
        logger.info("url={}",request.getRequestURL());
        //method
        logger.info("method={}",request.getMethod());
        //ip
        logger.info("method={}",request.getRemoteAddr());
        //类方法
        logger.info("class_method={}",joinPoint.getSignature().getDeclaringTypeName()+"."+joinPoint.getSignature().getName());
        //参数
        logger.info("args={}",joinPoint.getArgs());
    }

    @After("log()")
    public void doAfter(){
        logger.info("222222222");
    }

}

如果需要获取返回的值:

@AfterReturning(returning = "object",pointcut = "log()")
public void doAfterReturning(Object object){
    logger.info("response={}",object);
}

==========异常处理

package com.imooc.girl.domain;

public class Result<T> {
    /*错误码*/
    private Integer code;
    /*提示信息*/
    private String msg;
    /*具体的内容*/
    private T data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
package com.imooc.girl.utils;

import com.imooc.girl.domain.Result;

public class ResultUtil {

    public static Result success(Object object){
        Result result=new Result();
        result.setCode(0);
        result.setMsg("成功");
        result.setData(object);
        return result;
    }

    public static Result success(){
        return success(null);
    }

    public static Result error(Integer code,String msg){
        Result result=new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

}
/**
 * 添加一个女生
 */
@PostMapping(value="/girls")
public Object girlAdd(@Valid Girl girl, BindingResult bindingResult){

    if (bindingResult.hasErrors()){
        return ResultUtil.error(1,bindingResult.getFieldError().getDefaultMessage());
    }

    girl.setCupSize(girl.getCupSize());
    girl.setAge(girl.getAge());

    return ResultUtil.success(girlRepository.save(girl));
}
public class GirlException extends RuntimeException {
    private Integer code;

    public GirlException(ResultEnum resultEnum){
        super(resultEnum.getMsg());
        this.code=resultEnum.getCode();
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
}
@ControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value=Exception.class)
    @ResponseBody
    public Result handle(Exception e){
        if (e instanceof GirlException){
            GirlException girlException=(GirlException) e;
            return ResultUtil.error(girlException.getCode(),girlException.getMessage());
        }else {
            return ResultUtil.error(-1,"未知错误");
        }
    }
}
public enum ResultEnum {

    UNKONW_ERROR(-1,"未知错误"),
    SUCCESS(0,"成功"),
    PRIMARY_SCHOOL(100,"你可能还在上小学"),
    MIDDLE_SCHOOL(101,"你可能在上初中");


    private Integer code;
    private String msg;


    ResultEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
@Service
public class GirlService {

    @Autowired
    private GirlRepository girlRepository;

    @Transactional
    public void insertTwo(){
        try{
            Girl girlA=new Girl();
            girlA.setCupSize("A");
            girlA.setAge(18);
            girlRepository.save(girlA);

            Girl girlB=new Girl();
            girlB.setCupSize("BBB");
            girlB.setAge(19);
            girlRepository.save(girlB);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public void getAge(Integer id){
        Girl girl=girlRepository.getOne(id);
        Integer age=girl.getAge();
        if (age<10){
            //返回“你还在上小学吧”
            throw new GirlException(ResultEnum.PRIMARY_SCHOOL);
        }else if(age>10 && age<16){
            //返回“你可能在上初中“
            throw new GirlException(ResultEnum.MIDDLE_SCHOOL);
        }
    }
}

1.由于需要统一的返回格式,所以,封装了 返回对象Result

2.由于代码封装成功、失败等。高重复动作,封装工具类ResultUtil。

3.由于在逻辑处理时,牵扯很多种非法状态。service进行判断,获取逻辑--》返回controller,判断状态继续处理。

改良:service逻辑判断非法,抛出异常-->controller继续抛出-->统一异常类进行处理,调用工具类。

4.由于Exception只能有描述,没有状态值。难以返回。自定义GrilException(id+msg)。

5.由于每次都要输入状态值,状态描述。为了统一管理,将其封装到enum(数据字典),统一管理

今天关于SpringBoot 使用 WEB 进阶springboot webjars的分享就到这里,希望大家有所收获,若想了解更多关于idea:spring initializr 无 web 勾选,maven 方式搭建 springboot 项目。jdk7 创建 springboot 项目的版本不兼容问题。、java-study-springboot-基础学习-05-springboot web开发、springboot jdk11 spring-boot-starter-webflux 启动报错、springboot 之web进阶等相关知识,可以在本站进行查询。

本文标签: