spring boot 文档学习笔记day01

1.在pom.xml中使用spring-boot-starter-parent的作用:

Maven users can inherit from the spring-boot-starter-parent project to obtain sensible defaults. The parent project provides the following features:

  • Java 1.8 as the default compiler level.
  • UTF-8 source encoding.
  • A Dependency Management section, inherited from the spring-boot-dependencies pom, that manages the versions of common dependencies. This dependency management lets you omit <version> tags for those dependencies when used in your own pom.
  • Sensible resource filtering.
  • Sensible plugin configuration (exec plugin, Git commit ID, and shade).
  • Sensible resource filtering for application.properties and application.yml including profile-specific files (for example, application-dev.properties and application-dev.yml)

2.pom.xml里面有哪些配置,太多了,网址:

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-dependencies/pom.xml

3.启动类的位置最好在最外层的包中:

We generally recommend that you locate your main application class in a root package above other classes. The @EnableAutoConfiguration annotation is often placed on your main class, and it implicitly defines a base “search package” for certain items. For example, if you are writing a JPA application, the package of the @EnableAutoConfiguration annotated class is used to search for @Entity items.

Using a root package also lets the @ComponentScan annotation be used without needing to specify a basePackage attribute. You can also use the @SpringBootApplication annotation if your main class is in the root package.

The following listing shows a typical layout:

com

+- example

+- myapplication

+- Application.java

|

+- customer

|   +- Customer.java

|   +- CustomerController.java

|   +- CustomerService.java

|   +- CustomerRepository.java

|

+- order

+- Order.java

+- OrderController.java

+- OrderService.java

+- OrderRepository.java

4.尽量使用java配置,避免使用xml配置

You need not put all your @Configuration into a
single class. The @Import annotation can be used to import additional configuration classes.
Alternatively, you can use @ComponentScan to automatically pick up all Spring components, including @Configuration classes.

If you absolutely must use XML based configuration, we recommend
that you still start with a @Configuration class. You can then use
an @ImportResource annotation to load XML configuration files.

5.自动配置

You need to opt-in to auto-configuration by
adding the @EnableAutoConfiguration or @SpringBootApplication annotations to one of your @Configuration classes.,只添加到一个即可

 

6.排除不需要自动配置的类

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

或者

you can also control the list of auto-configuration classes to exclude by using the spring.autoconfigure.exclude property.

7.Bean注入容器

If you structure your code as suggested above (locating your application class in a root package), you can add @ComponentScan without any arguments. All of your application components (@Component, @Service, @Repository, @Controller etc.) are automatically registered as Spring Beans.

8. @SpringBootApplication代替常用几个的注解

The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration, and @ComponentScan with their default attributes

9.开发工具

The spring-boot-devtools module can be included in any project to provide additional development-time features.

<dependencies>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-devtools</artifactId>

<optional>true</optional>

</dependency>

</dependencies>

支持代码修改后重新加载启动,如果不需要:

If you do not want to use the restart feature, you can disable it by using the spring.devtools.restart.enabled property. In most cases, you can set this property in your application.properties (doing so still initializes the restart classloader, but it does not watch for file changes).

If you need to completely disable restart support (for example, because it does not work with a specific library), you need to set the spring.devtools.restart.enabled System property to false before calling SpringApplication.run(…?), as shown in the following example:

public static void main(String[] args) {

System.setProperty("spring.devtools.restart.enabled", "false");

SpringApplication.run(MyApp.class, args);

}

在开过程中经常修改但是不想启动,application.properties里面设置指定的文件修改才重启:

#重启的文件resouces文件夹中新建文件restart.trigger并设置

spring.devtools.restart.trigger-file=restart.trigger

这样只有在restart.trigger这个文件更改时才重新启动

原文地址:https://www.cnblogs.com/yueguangmoliya/p/8564017.html

时间: 2024-10-11 11:05:47

spring boot 文档学习笔记day01的相关文章

Spring3.0官网文档学习笔记(五)--3.3

3.3 概述 Table 3.1. The bean definition Property Explained in... class Section 3.3.2, "Instantiating beans" name Section 3.3.1, "Naming beans" scope Section 3.5, "Bean scopes" constructor arguments Section 3.4.1, "Dependen

Spring3.0官网文档学习笔记(六)--3.4.1

3.4 依赖 3.4.1 依赖注入 依赖注入两种方式:基于构造器的DI.基于setter方法的DI. 3.4.1.1 基于构造器的DI 参数是引入对象,且之前不存在父-子类关系: package x.y; public class Foo { public Foo(Bar bar, Baz baz) { // ... } } <beans> <bean id="foo" class="x.y.Foo"> <constructor-arg

Spring3.0官网文档学习笔记(七)--3.4.2

3.4.2 依赖与配置的细节 3.4.2.1  Straight values (primitives, Strings, and so on) JavaBeans PropertyEditors被用来转换这些value到实际的类型.? <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <

Spring3.0官网文档学习笔记(四)--3.1~3.2.3

3.1 Spring IoC容器与Beans简介 BeanFactory接口提供对任意对象的配置: ApplicationContext是BeanFactory的子接口,整合了Spring Aop功能,消息资源控制,事件发布,应用层特殊的上下文(在web应用中) 由IoC容器实例化.组装.管理的对象都是Bean 3.2 容器概述 org.springframework.context.ApplicationContext代表Spring IoC容器,并且负责通过读取配置元数据来实例化.配置.组装

Spring3.0官网文档学习笔记(八)--3.4.3~3.4.6

3.4.3 使用depends-on 使用depends-on可以强制使一个或多个beans先初始化,之后再对这个bean进行初始化. 多个bean之间用",".";"." "隔开. <bean id="beanOne" class="ExampleBean" depends-on="manager"/> <bean id="manager" cla

Spring3.0官网文档学习笔记(二)

1.3 使用场景 典型的成熟的spring web应用 spring使用第三方框架作为中间层 远程使用场景 EJB包装 1.3.1 依赖管理.命名规则(包) spring-*.jar *号代表的是模块的简写,如:spring-core, spring-webmvc, spring-jms 可以在四个不同的地方找到Spring: http://www.springsource.org/downloads/community  所有的jar包被打包成zip,名称从3.0开始是: org.spring

Spring3.0官网文档学习笔记(一)

Part 1 Spring框架概述 Spring是模块化的,在应用中只需要引入你所需要用到的模块的jar包,其余的jar包不用引入. spring框架支持声明式的事务管理,通过RMI或web service访问你的逻辑,还有许多种方式保存数据. spring被设计成非侵入式的. 1.Spring框架简介 Spring框架提供了应用开发的基础部分,使得我们可以集中精神在业务开发层上. POJOS:plain old Java objects Spring允许创建非侵入式的POJO.这个特性支持Ja

20140602-XML之Schema文档学习笔记

20140602-XML之Schema文档学习笔记 一.Schema约束 几个重要知识: 1.namespace 相当于schema文件的id.Namespace是一个概念,并没有这个属性. 2.targetNamespace属性 注意:这个属性只在schema文档中出现.用来指定schema文档的namespace的值. 3.xmlns属性(非常重要,用于引入一个约束) 引入一个约束,它的值是一个schema文档的targetNamespace值(确切地说,是targetNamespace的属

通过程序校验xml文档学习笔记

校验xml文档,可以通过程序来校验,利用一段js代码即可. 各行代码的含义已经写出,运行这个html文件,检验如下xml代码: 结果如下: 如果xml文档出现错误: 结果如下: 其中,obj.async=false是关闭对象的异步加载模式,所谓异步是加载一句解释一句,同步是加载完成后再解释.