标签:connector autoconf log4 soc pom jersey caching ocs restful
Spring 2.x 时代:随着 JDK 1.5 带来的注解支持,Spring2.x 可以使用注解对 Bean 进行申明和注入,大大的减少了 xml 配置文件,同时也大大简化了项目的开发。
那么,问题来了,究竟是应该使用 xml 还是注解呢?最佳实践:在上述环境下,Spring Boot 应运而生。它使用“习惯优于配置”(项目中存在大量的配置,此外还内置了一个习惯性的配置,让你无需手动进行配置)的理念让你的项目快速的运行起来。使用 Spring Boot 很容易创建一个独立运行(运行 Jar,内嵌 Servlet 容器)准生产级别的基于 Spring 框架的项目,使用 Spring Boot 你可以不用或者只需很少的 Spring 配置。(减少了配置文件)
新建 Spring Initializr 项目
main()
方法:是一个标准的 Java 应用的 main 方法,主要作用是作为项目启动的入口。
我们在 src/main/resources
目录下新建一个 banner.txt
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---‘\____
.‘ \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ‘‘\---/‘‘ | |
\ .-\__ `-` ___/-. /
___`. .‘ /--.--\ `. . __
."" ‘< `.___\_<|>_/___.‘ >‘"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-‘======
`=---=‘
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
佛祖保佑 永无BUG
再次启动springboot项目后图案就会变成上面的图案
Spring Boot项目使用一个全局的配置文件 application.properties
或者是 application.yml
,在resources
目录下或者类路径下的 /config
下,一般我们放到 resources
下。
修改 tomcat 的端口为 9090,并将默认的访问路径 "/" 修改为 "boot",可以在 application.properties
中添加:
server.port=9090
server.context-path=/boot
或在 application.yml 中添加:
server:
port: 9090
context-path: /boot #虚拟目录也就是我们学过的自定义的命名空间只不过这里是全局的
测试效果
修改 DispatcherServlet 的规则为:*.html
server:
port: 9090
context-path: /boot #虚拟目录也就是我们学过的自定义的命名空间只不过这里是全局的
servlet-path: "*.html" #后缀必须以.html结尾
测试效果
starter pom(就是pom.xml文件)
Spring Boot 为我们提供了简化企业级开发绝大多数场景的 starter pom ,只要使用了应用场景所需要的 starter pom ,相关的技术配置将会消除,就可以得到 Spring Boot 为我们提供的自动配置的 Bean。
官方提供的 starter pom
Name |
Description |
Pom |
|
Core starter, including auto-configuration support, logging and YAML |
|
|
Starter for JMS messaging using Apache ActiveMQ |
|
|
Starter for using Spring AMQP and Rabbit MQ |
|
|
Starter for aspect-oriented programming with Spring AOP and AspectJ |
|
|
Starter for JMS messaging using Apache Artemis |
|
|
Starter for using Spring Batch |
|
|
Starter for using Spring Framework’s caching support |
|
|
Starter for using Spring Cloud Connectors which simplifies connecting to services in cloud platforms like Cloud Foundry and Heroku |
|
|
Starter for using Cassandra distributed database and Spring Data Cassandra |
|
|
Starter for using Couchbase document-oriented database and Spring Data Couchbase |
|
|
Starter for using Elasticsearch search and analytics engine and Spring Data Elasticsearch |
|
|
Starter for using GemFire distributed data store and Spring Data GemFire |
|
|
Starter for using Spring Data JPA with Hibernate |
|
|
Starter for using Spring Data LDAP |
|
|
Starter for using MongoDB document-oriented database and Spring Data MongoDB |
|
|
Starter for using Neo4j graph database and Spring Data Neo4j |
|
|
Starter for using Redis key-value data store with Spring Data Redis and the Jedis client |
|
|
Starter for exposing Spring Data repositories over REST using Spring Data REST |
|
|
Starter for using the Apache Solr search platform with Spring Data Solr |
|
|
Starter for building MVC web applications using FreeMarker views |
|
|
Starter for building MVC web applications using Groovy Templates views |
|
|
Starter for building hypermedia-based RESTful web application with Spring MVC and Spring HATEOAS |
|
|
Starter for using Spring Integration |
|
|
Starter for using JDBC with the Tomcat JDBC connection pool |
|
|
Starter for building RESTful web applications using JAX-RS and Jersey. An alternative to |
|
|
Starter for using jOOQ to access SQL databases. An alternative to |
|
|
Starter for JTA transactions using Atomikos |
|
|
Starter for JTA transactions using Bitronix |
|
|
Spring Boot Narayana JTA Starter |
|
|
Starter for using Java Mail and Spring Framework’s email sending support |
|
|
Starter for building web applications using Spring Mobile |
|
|
Starter for building MVC web applications using Mustache views |
|
|
Starter for using Spring Security |
|
|
Starter for using Spring Social Facebook |
|
|
Stater for using Spring Social LinkedIn |
|
|
Starter for using Spring Social Twitter |
|
|
Starter for testing Spring Boot applications with libraries including JUnit, Hamcrest and Mockito |
|
|
Starter for building MVC web applications using Thymeleaf views |
|
|
Starter for using Java Bean Validation with Hibernate Validator |
|
|
Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container |
|
|
Starter for using Spring Web Services |
|
|
Starter for building WebSocket applications using Spring Framework’s WebSocket support |
Name |
Description |
Pom |
|
Starter for using Spring Boot’s Actuator which provides production ready features to help you monitor and manage your application |
|
|
Starter for using the CRaSH remote shell to monitor and manage your application over SSH. Deprecated since 1.5 |
Name |
Description |
Pom |
|
Starter for using Jetty as the embedded servlet container. An alternative to |
|
|
Starter for using Log4j2 for logging. An alternative to |
|
|
Starter for logging using Logback. Default logging starter |
|
|
Starter for using Tomcat as the embedded servlet container. Default servlet container starter used by |
|
|
Starter for using Undertow as the embedded servlet container. An alternative to |
Spring Boot 对各种日志框架都做了支持,我们可以通过配置来修改默认的日志的配置
默认情况下,Spring Boot 使用 Logback 作为日志框架
配置日志文件
logging:
file: ../logs/spring-boot-hello.log
level.org.springframework.web: DEBUG
关闭特定的自动配置
关闭特定的自动配置使用 @SpringBootApplication 注解的 exclude 参数
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
说明:这里是关闭数据源的自动配置
标签:connector autoconf log4 soc pom jersey caching ocs restful
原文地址:https://www.cnblogs.com/chuanqi1995/p/11320299.html