💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### 5 springboot基础 习惯优于配置。 优点:快速构建项目,对主流框架无配置集成,可以独立运行而不需servlet容器,提供了运行时监控,提高了开发部署效率,与云计算天然集成; 添加spring boot的父级依赖,这样这个项目就是spring boot项目了。 pom:parent>groupId>org.springframework.boot; parent>artifactId>spring-boot-starter-parent; ~~~ <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> ~~~ web支持的starter pom:spring-boot-starter-web ~~~ <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> ~~~ spring boot的编译插件pom:spring-boot-maven-plugin ~~~ <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> ~~~ 还需要添加ch.qos.back和slf4j的pom: ~~~ <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> <scope>test</scope> </dependency> ~~~ 使用 mvn spring-boot:run进行程序运行,或者运行入口类; ### 6 springboot 核心 使用banner.txt修改启动banner; spring boot reference 提供了spring boot都支持的pom内容,spring-boot-starter-xxx[-xxx]; 常规属性配置:在application.yml中配置属性,使用@Value("${book.name}")就可以注入;可以进行类型转换,但是如果转换出错,系统将崩溃; 类型安全的配置:使用Bean进行属性的获取,在Bean上面添加@ConfigurationProperties(prefix="a.b"),在Bean中设置属性名称,系统会自动注入属性值。如果属性文件不是application.yml,可以通过locations设置属性文件位置。 Profie是Spring对不同的环境提供不同的支持,application-dev.yml和application-prod.yml,在application.yml中进行spring.profiles.active=dev设置; @EnableAutoConfiguration让Spring Boot根据类路径中的jar包依赖为当前项目进行自动配置;