Spring boot 第四章 全局配置

Spring Boot项目使用一个全局的配置文件application.properties或者是application.yml,在resources目录

下或者类路径下的/config下,一般我们放到resources下。

1、修改tomcat的端口为8088

输入图片说明

启动后

输入图片说明

重新启动看效果

2、修改DispatcherServlet

Spring boot 2.x 由原来的server.servlet-path 改为server.servlet.path

但是测试发现无效。不知道为啥

3、spring boot properties

放个大招

spring boot docs

全局注解docs:spring boot properties

application配置文档

4、starter pom

spring boot 为我们提供了简化企业级开发绝大数场景的starter pom, 只要使用了应用场景所需要的starter pom ,相关的技术配置将会消除,就可以得到Spring boot 为我们提供的自动配置的bean

spring boot 官方starter pom

spring-boot-starter	                           // springboot核心starter ,包括自动配置,日志,yaml配置文件的支持
spring-boot-starter-activemq                 // Starter for JMS messaging using Apache ActiveMQ
spring-boot-starter-artemis                   // Starter for JMS messaging using Apache Artemis
spring-boot-starter-amqp	                   // 使用spring-rabbit支持AMQP
spring-boot-starter-aop	                   // 使用AOP和AspectJ支持面向切面编程

spring-boot-starter-remote-shell	           // 提供基于ssh协议的监控和管理

spring-boot-starter-batch	                   // 对springBatch支持
spring-boot-starter-cache	                   // 对SpringCache抽象的支持
spring-boot-starter-cloud-connectors	   // 对云平台(Cloud Foundry ,Heroku)提供的服务简化的连接方式
spring-boot-starter-data-cassandra.      // Starter for using Cassandra distributed database and Spring Data Cassandra
spring-boot-starter-data-cassandra-reactive // Starter for using Cassandra distributed database and Spring Data Cassandra Reactive
spring-boot-starter-data-couchbase      // Starter for using Couchbase document-oriented database and Spring Data Couchbase
spring-boot-starter-data-couchbase-reactive  // Starter for using Couchbase document-oriented database and Spring Data Couchbase Reactive
spring-boot-starter-data-elasticsearch.   // 对spring-data-elasticsearch的支持

spring-boot-starter-data-jpa	            // 对jpa的支持,包括spring-data-jap,spring-orm,Hibernate
spring-boot-starter-data-ldap                // Starter for using Spring Data LDAP
spring-boot-starter-data-mongodb         // 通过spring-data-mongodb对mongodb的支持
spring-boot-starter-data-mongodb-reactive //Starter for using MongoDB document-oriented database and Spring Data MongoDB Reactive
spring-boot-starter-data-neo4j              // Starter for using Neo4j graph database and Spring Data Neo4j
spring-boot-starter-data-redis               // Starter for using Redis key-value data store with Spring Data Redis and the Lettuce client
spring-boot-starter-data-redis-reactive  // Starter for using Redis key-value data store with Spring Data Redis reactive and the Lettuce client
spring-boot-starter-data-rest	            // 通过spring-data-rest-webmvc对spring Data reposity暴露为REST形式的服务
spring-boot-starter-data-solr	            // 通过spring-data-solr对Apache Solr的支持
spring-boot-starter-data-freemaker	    // 对Freemaker的支持
spring-boot-starter-data-groovy-templates	 // 对Groovy模版引擎的支持
spring-boot-starter-hateoas	            // 通过spring-hateoas对基于HATEOAS的REST形式的网络服务的支持
spring-boot-starter-hornetq	            // 通过HornetQ对JMS的支持
spring-boot-starter-integration	            // 对系统集成框架spring-integration的支持
spring-boot-starter-jdbc	                    // 对JDBC数据库的支持
spring-boot-starter-jersey	                    // 对Jersey REST形式的网络服务的支持
spring-boot-starter-jooq                        // Starter for using jOOQ to access SQL databases. An alternative to spring-boot-starter-data-jpa or spring-boot-starter-jdbc
spring-boot-starter-json                        // Starter for reading and writing json
spring-boot-starter-jta-atomikos	    // 通过Atomikos对分布式事物的支持
spring-boot-starter-jta-bitronix	            // 通过Bitronix对分布式事物的支持
spring-boot-starter-jta-narayana            // Starter for JTA transactions using Narayana
spring-boot-starter-mail	                    // 对spring mail的支持
spring-boot-starter-mustache	            // 对Mustache模版引擎的支持
spring-boot-starter-security	            // 对spring-security的支持
spring-boot-starter-social-facebook	    // 通过spring-social-facebook 对facebook的支持
spring-boot-starter-social-twitter	    // 通过spring-social-twitter 对twitter的支持
spring-boot-starter-social-linkedin	    // 通过spring-social-linkedin 对linkedin的支持
spring-boot-starter-thymeleaf	            // 对Thymeleaf模版引擎的支持,包含于spring的整合配置
spring-boot-starter-velocity	            // 对velocity模版引擎的支持
spring-boot-starter-web	                    // 对web项目开发的支持,包含tomcat和spring-webmvc
spring-boot-starter-Tomcat	            // springboot默认容器tomcat
spring-boot-starter-Jetty	                    // jetty容器
spring-boot-starter-undertow	            // Undertow容器
spring-boot-starter-logging	            // 默认日志输出框架Logback
spring-boot-starter-log4j	                    // 支持log4j
spring-boot-starter-websocket	            // websocket的支持
spring-boot-starter-ws	                    // spring webservice的支持

5、spring boot xml 配置文件

Spring boot 提倡零配置,即无xml配置,但是实际项目中,可能有一些特殊要求,你必须使用xml配置,这时我们可以通过Spring 提供@ImportResource来家在xml配置,例如

@ImportResource({"classpath:some-context.xml","classpath:another-context.xml"})

6、spring boot 日志

spring boot 对各种日志框架做了支持,我们可以通过配置来修改默认的日志配置:

logging.level.org.springframework=debug

格式:

loggin.level.* =

猜你喜欢

转载自my.oschina.net/u/3136594/blog/1789600