SpringBoot的相关配置及相关注解

server.port 配置项目的端口
server.contextPath 项目的名称

spring.http.encoding.charset 配置http请求的编码
spring.http.encoding.enabled = true
spring.http.encoding.force = true

#log
logging.file=/export/log
logging.level.root=INFO
logging.level.org.springframework.web=INFO
logging.level.sample.mybatis.mapper=TRACE

#关闭启动Logo
spring.main.banner-mode=off

//datasorce configration
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

访问的log
spring boot默认访问的时候会是一个绿色叶子的图标,
该图标可以换掉,只需将自定义ico图标放在resources目录下即可
注:名称需要设置为默认名称 favicon.ico

#mybatis配置
mybatis.type-aliases-package=com.sam.project..model
mybatis.mapper-locations=classpath:mapper/
.xml

Springboot的子项目

1)spring-boot-starter 这是Spring Boot的核心启动器,包含了自动配置)日志和YAML。
2)spring-boot-starter-actuator 帮助监控和管理应用。
3)spring-boot-starter-amqp 通过spring-rabbit来支持AMQP协议(Advanced Message Queuing Protocol)。
4)spring-boot-starter-aop 支持面向切面的编程即AOP,包括spring-aop和AspectJ。
5)spring-boot-starter-artemis 通过Apache Artemis支持JMS的API(Java Message Service API)。
6)spring-boot-starter-batch 支持Spring Batch,包括HSQLDB数据库。
7)spring-boot-starter-cache 支持Spring的Cache抽象。
8)spring-boot-starter-cloud-connectors 支持Spring Cloud Connectors,简化了在像Cloud Foundry或Heroku这样的云平台上连接服务。
9)spring-boot-starter-data-elasticsearch 支持ElasticSearch搜索和分析引擎,包括spring-data-elasticsearch。
10)spring-boot-starter-data-gemfire 支持GemFire分布式数据存储,包括spring-data-gemfire。
11)spring-boot-starter-data-jpa 支持JPA(java Persistence API),包括spring-data-jpa)spring-orm)hibernate。
12)spring-boot-starter-data-MongoDB 支持mongodb数据,包括spring-data-mongodb。
13)spring-boot-starter-data-rest 通过spring-data-rest-webmvc,支持通过REST暴露Spring Data数据仓库。
14)spring-boot-starter-data-solr 支持Apache Solr搜索平台,包括spring-data-solr。
15)spring-boot-starter-freemarker 支持FreeMarker模板引擎。
16)spring-boot-starter-groovy-templates 支持Groovy模板引擎。
17)spring-boot-starter-hateoas 通过spring-hateoas支持基于HATEOAS的RESTful Web服务。
18)spring-boot-starter-hornetq 通过HornetQ支持JMS。
19)spring-boot-starter-integration 支持通用的spring-integration模块。
20)spring-boot-starter-jdbc 支持JDBC数据库。
21)spring-boot-starter-jersey 支持Jersey RESTful Web服务框架。
22)spring-boot-starter-jta-atomikos 通过Atomikos支持JTA分布式事务处理。
23)spring-boot-starter-jta-bitronix 通过Bitronix支持JTA分布式事务处理。
24)spring-boot-starter-mail 支持javax.mail模块。
25)spring-boot-starter-mobile 支持spring-mobile。
26)spring-boot-starter-mustache 支持Mustache模板引擎。
27)spring-boot-starter-Redis 支持redis键值存储数据库,包括spring-redis。
28)spring-boot-starter-security 支持spring-security。
29)spring-boot-starter-social-facebook 支持spring-social-facebook
30)spring-boot-starter-social-linkedin 支持pring-social-linkedin
31)spring-boot-starter-social-twitter 支持pring-social-twitter
32)spring-boot-starter-test 支持常规的测试依赖,包括JUnit)Hamcrest)Mockito以及spring-test模块。
33)spring-boot-starter-thymeleaf 支持Thymeleaf模板引擎,包括与Spring的集成。
34)spring-boot-starter-velocity 支持Velocity模板引擎。
35)spring-boot-starter-web S支持全栈式Web开发,包括Tomcat和spring-webmvc。
36)spring-boot-starter-websocket 支持WebSocket开发。
37)spring-boot-starter-ws 支持Spring Web Services。Spring Boot应用启动器面向生产环境的还有2种,具体如下:
1)spring-boot-starter-actuator 增加了面向产品上线相关的功能,比如测量和监控。
2)spring-boot-starter-remote-shell 增加了远程ssh shell的支持。

最后,Spring Boot应用启动器还有一些替换技术的启动器,具体如下:
1)spring-boot-starter-jetty
引入了Jetty HTTP引擎(用于替换Tomcat)。

2)spring-boot-starter-log4j
支持Log4J日志框架。

3)spring-boot-starter-logging
引入了Spring Boot默认的日志框架Logback。

4)spring-boot-starter-tomcat
引入了Spring Boot默认的HTTP引擎Tomcat。

5)spring-boot-starter-undertow
引入了Undertow HTTP引擎(用于替换Tomcat)。

常用注解
@Configuration
相当于传统的xml配置文件,如果有些第三方库需要用到xml文件,建议仍然通过@Configuration类作为项目的配置主类——可以使用@ImportResource注解加载xml配置文件

@EnableAutoConfiguration
Spring Boot自动配置(auto-configuration):尝试根据你添加的jar依赖自动配置你的Spring应用。例如,如果你的classpath下存在HSQLDB,并且你没有手动配置任何数据库连接beans,那么我们将自动配置一个内存型(in-memory)数据库”。你可以将@EnableAutoConfiguration或者@SpringBootApplication注解添加到一个@Configuration类上来选择自动配置。如果发现应用了你不想要的特定自动配置类,你可以使用@EnableAutoConfiguration注解的排除属性来禁用它们。

@ComponentScan
表示将该类自动发现扫描组件。个人理解相当于,如果扫描到有@Component、@Controller、@Service等这些注解的类,并注册为Bean,可以自动收集所有的Spring组件,包括@Configuration类。我们经常使用@ComponentScan注解搜索beans,并结合@Autowired注解导入。可以自动收集所有的Spring组件,包括@Configuration类。我们经常使用@ComponentScan注解搜索beans,并结合@Autowired注解导入。如果没有配置的话,Spring Boot会扫描启动类所在包下以及子包下的使用了@Service,@Repository等注解的类

@Component
可配合CommandLineRunner使用,在程序启动后执行一些基础任务。

@RestController
注解是@Controller和@ResponseBody的合集,表示这是个控制器bean,并且是将函数的返回值直 接填入HTTP响应体中,是REST风格的控制器。

@Autowired 自动导入

@PathVariable 获取参数。

@JsonBackReference 解决嵌套外链问题

@RepositoryRestResourcepublic 配合spring-boot-starter-data-rest使用。

@Import:用来导入其他配置类。

@ImportResource:用来加载xml配置文件。

@Autowired:自动导入依赖的bean

@Service:一般用于修饰service层的组件

@Repository:使用@Repository注解可以确保DAO或者repositories提供异常转译,这个注解修饰的DAO或者repositories类会被ComponetScan发现并配置,同时也不需要为它们提供XML配置项。

@Bean:用@Bean标注方法等价于XML中配置的bean。

@Value:注入Spring boot application.properties配置的属性的值。

猜你喜欢

转载自blog.csdn.net/qq_36755772/article/details/88954181
今日推荐