1 Star 0 Fork 0

huaitian / ztest-springboot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

SpringBoot学习笔记

[TOC]

1、基础

1.基本尝试
2.banner
3.server.port
4.server.context-path/contextPath/CONTEXT_PATH

2、从properties文件中加载内容

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

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

3、把properties文件映射成Bean

@Component
@ConfigurationProperties(prefix = "author", locations = {"classpath:config/author.properties"})
public class AuthorSettings {

    private String name;
    private Long age;

    public String getName() {
        return name;
    }

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

    public Long getAge() {
        return age;
    }

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

4、Profiles的使用

spring.profiles.active=dev

5、AutoConfig

1) 依赖

<dependency>
    <groupId>person.zt</groupId>
	<artifactId>spring-boot-starter-hello</artifactId>
	<version>1.0-SNAPSHOT</version>
</dependency>

2)自动配置实现

@Configuration
@EnableConfigurationProperties(HelloServiceProperties.class)
@ConditionalOnClass(HelloService.class)
@ConditionalOnProperty(prefix = "hello", value = "enabled", matchIfMissing = true)
public class HelloServiceAutoConfiguration {

    @Autowired
    private HelloServiceProperties helloServiceProperties;

    @Bean
    @ConditionalOnMissingBean(HelloService.class)
    public HelloService helloService(){
        System.out.println(">>>>我的自动配置开始生成 HelloService 的Bean了!!!");
        HelloService helloService = new HelloService();
        helloService.setMsg(helloServiceProperties.getMsg());
        return helloService;
    }
}

3)spring.factories

  • resources/META-INF/spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
  person.zt.spring_boot_starter_hello.HelloServiceAutoConfiguration

空文件

简介

SpringBoot练习整合,包含自动配置的测试 展开 收起
Java
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/huaitian/ztest-springboot.git
git@gitee.com:huaitian/ztest-springboot.git
huaitian
ztest-springboot
ztest-springboot
dev

搜索帮助