SpringBoot随手笔记

1.@EnableAutoConfiguration //开启自动配置

2.[Tomcat].[localhost].[/] 所以访问路径是/(根目录)

3.改变访问路径

server:
  port: 8088
  context-path: /www

4.取自定义值的配置

Book:(yml文件)
  author: nat
  name: springboot
=============================
@Controller
public class BookController {

    @Value("${book.author}")
    private String author;

    @Value("${book.name}")
    private String name;

    @RequestMapping("/bookIfno")
    @ResponseBody
    public String showInfo() {
        return name+":"+author;
    }
}
(使用注解配置)
@ConfigurationProperties(prefix = "book")
@Controller
public class BookController {

//    @Value("${book.author}")
    private String author;//使用ConfigurationProperties 属性名与配置的名字要相同

//    @Value("${book.name}")
    private String name;

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @RequestMapping("/bookIfno")
    @ResponseBody
    public String showInfo() {
        return name+":"+author;
    }
}

5.Profile配置

1.Profile是针对不同环境进行不同的配置(全局)
application-*.properties
*:prod,sit,dev
2.通过application.properties中设置spring.profiles.active=prod


编写配置文件

6.日志信息(两种方式)

1.SpringBoot中使用log4j要进行包排除。

<!-- log4j -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
     </dependency>    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j</artifactId>
        <version>1.3.8.RELEASE</version>
    </dependency>

具体:[https://www.cnblogs.com/30go/p/8443435.html](https://www.cnblogs.com/30go/p/8443435.html)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。