Spring 注解整理

1.核心容器(Core)

Spring Core 提供bean工厂 控制反转(IOC),利用IOC使配置与代码进行分离,降低耦合。

基于xml配置元数据; Spring 2.5引入了基于注释的配置元数据; 从Spring 3开始基于java配置,使用注解,

1.1@Configuration [kənˌfɪgəˈreɪʃn]

作用:配置spring容器(应用上下文),相当于把该类作为spring的xml配置文件中的 </beans/>,用于替换XML中配置beans。

用法:@Configuration标注在类上(此类为配置类)、接口。

注:用<context:component-scanbase-package=”XXX”/>扫描该类,最终我们可以在程序里用>@AutoWired或@Resource注解取得用@Bean注解的bean,和用xml先配置bean然后在程序里自动>注入一样。目的是减少xml里配置。

例1.1:(1)/*** desc:** @author zhoulk*         Date:  2018/6/25.*/public class Annotation {public void Show(){System.out.println("spring学习!");}}(2)配置类,用于替换xmlimport org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.Scope;/*** desc:** @author zhoulk*         Date:  2018/6/25.*         配置类,替换xml*/@Configurationpublic class ConfigurationDemo {// @Bean注解注册bean,同时可以指定初始化和销毁方法// @Bean(name="annotation",initMethod="start",destroyMethod="cleanUp")@Bean@Scope("prototype")public Annotation annotation() {return new Annotation();}}(3)import org.springframework.context.annotation.AnnotationConfigApplicationContext;import org.springframework.context.ApplicationContext;/*** desc:** @author zhoulk*         Date:  2018/6/25.**         注:报错*/public class TestConfiguration {public static void main(String[] args) {// @Configuration注解的spring容器加载方式,用AnnotationConfigApplicationContext替换ClassPathXmlApplicationContext//和使用ApplicationContext.xml加载的效果相同// ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");ApplicationContext context = new AnnotationConfigApplicationContext(ConfigurationDemo.class);//获取实例cAnnotation annotation =(Annotation) context.getBean("annotation");annotation.Show();}}

1.2@Bean

作用:@Bean注解一个方法,使其产生一个Bean,交于spring容器。等效于<bean id="id类名" class="类名"//>

用法:@Bean注解方法(该方法返回类型为对象)、注解类型上。配合@Configuration使用

例:配置类,用于替换xmlimport org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.Scope;/*** desc:** @author zhoulk*         Date:  2018/6/25.*         配置类,替换xml*/@Configurationpublic class ConfigurationDemo {// @Bean注解注册bean,同时可以指定初始化和销毁方法// @Bean(name="annotation",initMethod="start",destroyMethod="cleanUp")@Bean@Scope("prototype")//singleton:单例,默认值prototype:多例public Annotation annotation() {return new Annotation();}}

1.3@Import

作用:@Import是被用来整合所有在@Configuration注解中定义的bean配置

用法:@Import注解类(配置类)、接口。

例:import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.Import;@Configuration@Import({JavaConfigA.class,JavaConfigB.class})//JavaConfigA为配置类A,JavaConfigB配置类B。实现相同接口public class ParentConfig {//Any other bean definitions}

1.4 @ConstructorProperties [kənˈstrʌktə(r)]

作用:(不明)

用法:注解构造函数

例:@ConstructorProperties({"x","y"})public NewHello(String x, String y) {this.x = x;this.y = y;}

1.5 @Component [kəmˈpəʊnənt], @Repository [rɪˈpɒzətri] , @Service, @Controller

作用: @Component泛指组件,当组件不要好归类时,可以使用这个注解进行标注。 (把普通java对象实例化到spring容器中,相当于配置文件中的)

注:(@Service用于标注业务层组件

@Repository用于标注数据访问组件,即DAO组件

@Controller用于标注控制层组件,如Struts中的Action)

用法:@Component注解用于类或接口,用法相似与@Service。

例:@Component("userService") public class UserServiceImpl implements UserService{ private UserDao userDao; @Override public List<User> getUser() { return userDao.getUser(); } //标注在set方法上。 @Autowired public void setUserDao(@Qualifier("userDao") UserDao userDao) { //@Qualifier用于接口有多个实现类时,@Qualifier的参数必须是我们标注需要实现的@Service注解的名称。this.userDao = userDao; } } omponentScan

1.6@ComponentScan

作用:@ComponentScan会自动扫描包路径下面的所有@Controller、@Service、@Repository、@Component 注解的类

用法:@ComponentScan注解类(此类为配置类)、接口

属性:value指定扫描的包,includeFilters包含那些过滤,excludeFilters不包含那些过滤,>useDefaultFilters>默认的过滤规则是开启的.如果我们要自定义的话是要关闭的。其中@Filters是一个过滤器的接口。

@Filters 指过滤规则,FilterType指定过滤的规则(

FilterType.ANNOTATION:按照注解

FilterType.ASSIGNABLE_TYPE:按照给定的类型;

FilterType.ASPECTJ:使用ASPECTJ表达式

FilterType.REGEX:使用正则指定

FilterType.CUSTOM:使用自定义规则)

classes指定过滤的类

例:package com.guang.config;  import org.springframework.context.annotation.Bean;  
import org.springframework.context.annotation.ComponentScan;  
import org.springframework.context.annotation.ComponentScan.Filter;  
import org.springframework.context.annotation.Configuration;  
import org.springframework.context.annotation.FilterType;  
import com.guang.entity.Person;  @Configuration  
// @ComponentScan("包路径") 会自动扫描包路径下面的所有@Controller、@Service、@Repository、@Component 的类  
// includeFilters 指定包含扫描的内容  
// excludeFilters 指定不包含的内容  
// @Filter 指定过滤规则,type指定扫描的规则(注解,正则,自定义,ASPECTJ表达式),classes指定的扫描的规则类  
@ComponentScan(basePackages = {"com.guang"},  includeFilters = @Filter(type = FilterType.ANNOTATION, classes = {Controller.class}),  excludeFilters = @Filter(type = FilterType.ANNOTATION, classes = {Repository.class}),  includeFilters = @Filter(type = FilterType.CUSTOM, classes = {FilterCustom.class}),  useDefaultFilters = false)  
public class Myconfig {  @Bean("person")  public Person person01() {  return new Person("aiha", 25);  }  }  

1.7 @Required(为什么使用,什么场景?)

作用:@Required注解的set方法必须在xml文件进行配置(赋值),否则会包错BeanInitializationException。

用法:用于注解set方法。

例:package com.zlk.required;import org.springframework.beans.factory.annotation.Required;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;/*** desc:** @author zhoulk*         Date:  2018/6/26.*         测试@Required注解*/
public class Student {private String name;private String age;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getAge() {return age;}@Requiredpublic void setAge(String age) {this.age = age;}public static void main(String[] args) {ApplicationContext context = new ClassPathXmlApplicationContext("/resources/Beans.xml");Student student = (Student) context.getBean("student");System.out.println("Name : " + student.getName() );System.out.println("Age : " + student.getAge() );}
}配置文件Beans.xml:由于age用 @Required进行注解,配置文件中age必须有值。
(否则报错:Caused by: org.springframework.beans.factory.BeanInitializationException: Property 'age' is required for bean 'student')<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"><context:annotation-config/><!-- Definition for student bean --><bean id="student" class="com.zlk.required.Student"><!--    <property name="name"  value="Zara" />--><!-- try without passing age and check the result --><property name="age"  value="11"/></bean>
</beans>

1.8 @Autowired(Angular2中@Inject有类似效果,JAVA注解@Resource)

作用:@Autowired 注释,它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作。 通过 @Autowired的使用来消除 set ,get方法。,当无匹配的Bean时会报错。

注:@Autowired可配合@Qualifier("office")指定注入Bean的名称。@Resource(name = "manImpl")可直接指明实现类。使用时必须对包进行扫描,否则注入结果将未null。

@Resource默认按照名称方式进行bean匹配(装配对象名称),@Autowired默认按照类型方式进行bean匹配

用法:注解对象(常见),构造方法,方法,参数,域,注解类型上。

属性:required = false找不到匹配Bean时不报错。

byType:按类型装配,可以根据属性的类型,在容器中寻找根该类型匹配的bean.如果发现多个,那么将会抛出异常。如>果》没有找到,即属性值为null。

byName:按名称装配,可以根据属性的名称,在容器中寻找根该属性名相同的bean,如果没有找到,即属性值为null。

Constructor与byType的方式类似,不同之处在于它应用于构造器参数。如果在容器中没有找到与构造器参数类型一致的>bean,那么将会抛出异常。

Autodetect:通过bean类的自省机制来决定是使用constructor还是byType方式进行自动装配。如果发现默认的构造>器,那么将使用byType方式。

例:
@Service  
public class SequenceServiceImpl implements SequenceService {  @Autowired//@Qualifier("sequenceMapper")private SequenceMapper sequenceMapper;  @Resource(name = "manImpl")//注意是manImpl不是ManImpl,因为使用@Service,容器为我们创建bean时默认类名首字母小写  private Human human;  }  

1.9@Order

作用:@Order控制类的加载顺序。确定注入到array或者list中的顺序(待研究)

用法:注解类和接口,方法,域(?)。@Order(n),n越小,越先加载。

测试结果:@Order(5)类加载顺序,只有在配合@Configuration与@Bean使用时产生效果(配置类)。

例:
1、package com.zlk.order;
/*** desc:** @author zhoulk*         Date:  2018/6/27.*/
@Configuration
@Order(5)
public class Order1{private final int ORDERED = 1;@Beanpublic Servers1 show1(){System.out.println("Servers1");return new Servers1();}
}2、@Configuration
@Order(2)
public class Order2 {private final int ORDERED = 2;@Beanpublic Servers2 show2(){System.out.println("Servers2");return new Servers2();}
}3、public class Servers1{
}4、public class Servers2 {
}5.public class Test {public static void main(String[] args) {AnnotationConfigApplicationContext context =new AnnotationConfigApplicationContext("com.zlk.order");}
}

1.10 @Priority [praɪˈɒrəti](@Order效果相似,待研究)

1.11 @DependsOn

作用:@DependsOn用于强制初始化其他Bean。

用法:注解方法,类和接口。与@Bean一起使用。

例:public class DependsA {
}public class DependsB {
}@Configuration
@ComponentScan("com.zlk.dependsOn")
public class Test {@Beanpublic DependsB dependsB () {System.out.println("B");return new DependsB();}@Bean@DependsOn("dependsB")//强转先初始化dependsBpublic DependsA dependsA () {System.out.println("A");return new DependsA();}public static void main(String[] args) {new AnnotationConfigApplicationContext(Test.class);}
}

1.12@value

作用:为了简化读取properties文件中的配置值,spring支持@value注解的方式来获取,这种方式大大简化了项目配置,提高业务中的灵活性。

用法:注解方法,1、 @Value("#{对象.方法()}") 2、@Value("${配置文件配置项名称}")

例:import org.springframework.stereotype.Service; /** * 测试Bean */
@Service("userService") 
public class UserService { public int count() { return 10; } public int max(int size) { int count = count(); return count > size ? count : size; } 
}import org.springframework.beans.factory.InitializingBean; 
import org.springframework.beans.factory.annotation.Value; 
import org.springframework.stereotype.Component; @Component
public class AppRunner implements InitializingBean { /** * 引用一个配置项 */@Value("${app.port}") private int port; /** * 调用容器的一个bean的方法获取值 */@Value("#{userService.count()}") private int userCount; /** * 调用容器的一个bean的方法,且传入一个配置项的值作为参数 */@Value("#{userService.max(${app.size})}") private int max; /** * 简单的运算 */@Value("#{${app.size} <= '12345'.length() ? ${app.size} : '12345'.length()}") private int min; //测试 public void afterPropertiesSet() throws Exception { System.out.println("port : " + port); System.out.println("userCount : " + userCount); System.out.println("max : " + max); System.out.println("min : " + min); } 
}app.properties文件:
app.port=9090
app.size=3import org.springframework.context.annotation.AnnotationConfigApplicationContext; 
import org.springframework.context.annotation.ComponentScan; 
import org.springframework.context.annotation.PropertySource; @ComponentScan
@PropertySource("classpath:app.properties") 
public class App { public static void main( String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(App.class); context.close(); } 
}

1.13@Primary

作用:当一个接口有多个实现类时,且实现类都有类似@Service注解实现。此时如果对接口进行注入实现,将不能确定注入那个实现类,结果将会报错(若只有一个实现类实现了类似@Service的注解,将注入该实现类)。处理办法在需要实现注入的实现类上加@Primary。(效果等同在实现注入用@Autowired与 @Qualifier("sequenceMapper")注解)

用法:加到需要注入的实现类、接口、方法上。

例:
public interface S {String sing(String lyrics);}@Component // 加注解,让spring识别
public class S1 implements  S {public String sing(String s1){return "s1";}
}@Component // 加注解,让spring识别
@Primary//指明注入该实现类
public class S2 implements  S {public String sing(String s1){return "s2";}
}@Component
public class SingerService {@Autowiredprivate S s;//此时注入@Primary注解的实现类。
}

1.14@Qualifier

作用:一般配合@Autowired使用,指明需要实现注入的类(接口有多实现时使用)

用法:注解对象,类。@Qualifier("实现类名称")

例子见1.8对应的实例。

1.15@Genre

作用:与@Qualifier相似,但是可以用来注解形参(一个接口需要实现多个实现类注入时,作为辨别)

用法:注解对象,注解形参。@Genre(“实现类名称”)

例:public class MovieRecommender {@Autowired@Genre("Action")private MovieCatalog actionCatalog;private MovieCatalog comedyCatalog;@Autowiredpublic void setComedyCatalog(@Genre("Comedy") MovieCatalog comedyCatalog) {this.comedyCatalog = comedyCatalog;}
}

1.16 @Offline 作用:与@Qualifier相似

例:
public class MovieRecommender {@Autowired@Offlineprivate MovieCatalog offlineCatalog;// ...
}xml:
<bean class="example.SimpleMovieCatalog"><qualifier type="Offline"/><!-- inject any dependencies required by this bean -->
</bean>

1.17@MovieQualifier(未明白)

1.18@PostConstruct、@PreDestroy(待整理,效果未明白)

被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器调用一次,类似于Serclet的>inti()方法。被@PostConstruct修饰的方法会在构造函数之后,init()方法之前运行。

被@PreDestroy修饰的方法会在服务器卸载Servlet的时候运行,并且只会被服务器调用一次,类似于Servlet的>destroy()方法。被@PreDestroy修饰的方法会在destroy()方法之后运行,在Servlet被彻底卸载之前。(详见下面的>程序实践)

用法:注解方法

例:1、public class Product {private Integer price;private String name;@Resource(name = "typeB")private Type type;public Integer getPrice() {return price;}public void setPrice(Integer price) {this.price = price;}public Type getType() {return type;}public String getName() {return name;}public void setName(String name) {this.name = name;}@PostConstructpublic void init() {System.out.println("In init block of Product");}@PreDestroypublic void destroy() {System.out.println("In destroy block of Product");}
}2、public class Type {private String productType;public String getProductType() {return productType;}public void setProductType(String productType) {this.productType = productType;}
}3、public class MainApp {public static void main(String[] args) {AbstractApplicationContext context = new ClassPathXmlApplicationContext("resources/BeansJSRAnnotation.xml");Product product = (Product) context.getBean("product");System.out.println("Product Name : " + product.getName());System.out.println("Price : " + product.getPrice());Type productType = product.getType();System.out.println(product.getName() + " is of type:"+ productType.getProductType());context.registerShutdownHook();}
}4、xml配置BeansJSRAnnotation.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.2.xsd"><context:annotation-config /><!-- Definition for Product bean --><bean id="product" class="com.zlk.postConstruct_preDestroy.Product" init-method="init" destroy-method="destroy"><property name="name" value="ProductA" /><property name="price" value="400" /></bean><bean id="typeA" class="com.zlk.postConstruct_preDestroy.Type"><property name="productType" value="Export" /></bean><bean id="typeB" class="com.zlk.postConstruct_preDestroy.Type"><property name="productType" value="Import" /></bean>
</beans>

1.19 @AliasFor

作用:定义注解时,定义属性互为别名。 注:该注解互为别名的属性成对出现,有默认值,使用互为别名的属性时只能用其中的一个属性名。 用法:注解 注解属性的属性互为别名;

例:@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ContextConfiguration {@AliasFor("locations")String[] value() default {};@AliasFor("value")String[] locations() default {};//...
}

1.20 @Named

作用:用于辨别接口多实现时。

用法:作用于形参、类、接口。

例:1、import javax.inject.Inject;
import javax.inject.Named;public class SimpleMovieLister {private MovieFinder movieFinder;@Inject//注入Beanpublic void setMovieFinder(@Named("main") MovieFinder movieFinder) {this.movieFinder = movieFinder;}
}2、import javax.inject.Inject;
import javax.inject.Named;  
@Named("movieListener")  // @ManagedBean("movieListener") could be used as well
public class SimpleMovieLister {private MovieFinder movieFinder;@Injectpublic void setMovieFinder(MovieFinder movieFinder) {this.movieFinder = movieFinder;}// ...
}

1.21 @Nullable

作用:定义参数可以为空。 用法:注解形参。

例:public class SimpleMovieLister {@Injectpublic void setMovieFinder(@Nullable MovieFinder movieFinder) {...}
}

1.22@Scope

作用:作用范围。

用法:注解形参。@scope默认是单例模式(singleton),如@scope("singleton") 如果需要设置的话@scope("prototype")

1.singleton单例模式,全局有且仅有一个实例2.prototype原型模式,每次获取Bean的时候会有一个新的实例3.requestrequest表示该针对每一次HTTP请求都会产生一个新的bean,同时该bean仅在当前HTTP request内有效,配置实例:
request、session、global session使用的时候首先要在初始化web的web.xml中做如下配置:
如果你使用的是Servlet 2.4及以上的web容器,那么你仅需要在web应用的XML声明文件web.xml中增加下述ContextListener即可: 
<web-app>...<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class></listener>...
</web-app>4.sessionsession作用域表示该针对每一次HTTP请求都会产生一个新的bean,同时该bean仅在当前HTTP session内有效5.global session
global session作用域类似于标准的HTTP Session作用域,不过它仅仅在基于portlet的web应用中才有意义。Portlet规范定义了全局Session的概念,它被所有构成某个 portlet web应用的各种不同的portlet所共享。在global session作用域中定义的bean被限定于全局portlet Session的生命周期范围内。如果你在web中使用global session作用域来标识bean,那么web会自动当成session类型来使用。

1.23 @Lazy(未测试)

作用:lazy是是否懒加载,如果一个类不是启动就需要的就可以设置为懒加载,用的时候再初始化。 @Lazy用于指定该Bean是否取消预初始化。主要用于修饰Spring Bean类,用于指定该Bean的预初始化行为, 使用该Annotation时可以指定一个boolean型的value属性,该属性决定是否要预初始化该Bean

lazy代表延时加载,lazy=false,代表不延时,如果对象A中还有对象B的引用,会在A的xml映射文件中配置b的对象引>用,多对一或一对多,不延时代表查询出对象A的时候,会把B对象也查询出来放到A对象的引用中,A对象中的B对象是有>值的。

lazy=true代表延时,查询A对象时,不会把B对象也查询出来,只会在用到A对象中B对象时才会去查询,默认好像是>false,你可以看看后台的sql语句的变化就明白了,一般需要优化效率的时候会用到

用法:注解类;

例:@Lazy(true)
@Component
public class Chinese implements Person{//codes here
}

1.24@Profile(未测试)

作用:实际开发中用于替换开发、测试、正式环境。

用法:

例:package com.websystique.spring.configuration;import javax.sql.DataSource;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.datasource.DriverManagerDataSource;@Profile("Development")
@Configuration
public class DevDatabaseConfig implements DatabaseConfig {@Override@Beanpublic DataSource createDataSource() {System.out.println("Creating DEV database");DriverManagerDataSource dataSource = new DriverManagerDataSource();/** Set MySQL specific properties for Development Environment*/return dataSource;}
}<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"><context:component-scan base-package="com.websystique.spring"/><beans profile="Development"><import resource="dev-config-context.xml"/> </beans><beans profile="Production"><import resource="prod-config-context.xml"/></beans></beans>

1.25@Conditional(条件注解)

作用:满足特定条件时创建特定的Bean.

用法:如下

  @Bean@Conditional(WindowsCondition.class)//WindowsCondition类为判断条件public ListService windowsListService() {return new WindowsListService();
}

1.26@PropertySouce

作用:用于读取properties配置文件

用法:@PropertySource("classpath:config.properties") ,注解与类上。

例:package com.zlk.value;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.PropertySource;@ComponentScan//扫描注解
@PropertySource("classpath:resources/app.properties")//加载xml
public class App {@Value("${demo.url}")  private String mongodbUrl;  public static void main( String[] args) {AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(App.class);context.close();}
}

1.27@EnableLoadTimeWeaving

1.28@EventListener

作用:用于做事件监听(具体作用不清晰)。

用法:注解方法。

1.29@Async(未测试)

作用@Async标注的异步方法会在独立的现场中运行,调用者不用等其执行完,即可执行其他操作。

用法: 1启动方式:

基于Java配置的启用方式:

@Configuration
@EnableAsync
public class SpringAsyncConfig { ... }

基于XML配置文件的启用方式,配置如下:

<task:executor id="myexecutor" pool-size="5" />
<task:annotation-driven executor="myexecutor"/>

2基于@Async无返回值调用

 @Async  //标注使用  public void asyncMethodWithVoidReturnType() {  System.out.println("Execute method asynchronously. "  + Thread.currentThread().getName());  }  

1.30@NumberFormat、@DateTimeFormat

作用:数字与日期格式注解

注:@Number:定义数字相关的解析/格式化元数据(通用样式、货币样式、百分数样式),参数如下:style:用于指定样式类型,包括三种:Style.NUMBER(通用样式) Style.CURRENCY(货币样式) Style.PERCENT(百分数样式),默认Style.NUMBER;pattern:自定义样式,如patter="#,###";@DateTimeFormat:定义日期相关的解析/格式化元数据,参数如下:pattern:指定解析/格式化字段数据的模式,如”yyyy-MM-dd HH:mm:ss”iso:指定解析/格式化字段数据的ISO模式,包括四种:ISO.NONE(不使用)  ISO.DATE(yyyy-MM-dd) ISO.TIME(hh:mm:ss.SSSZ)  ISO.DATE_TIME(yyyy-MM-dd hh:mm:ss.SSSZ),默认ISO.NONE;style:指定用于格式化的样式模式,默认“SS”,具体使用请参考Joda-Time类库的org.joda.time.format.DateTimeFormat的forStyle的javadoc;优先级: pattern 大于 iso 大于 style。

用法:如下

例:public class FormatterModel {  @NumberFormat(style=Style.NUMBER, pattern="#,###")  private int totalCount;  @NumberFormat(style=Style.PERCENT)  private double discount;  @NumberFormat(style=Style.CURRENCY)  private double sumMoney;  @DateTimeFormat(iso=ISO.DATE)   private Date registerDate;  @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")   private Date orderDate;  //省略getter/setter  
}   

1.31@Aspect(理解模糊)

作用:做AOP(面向切面)管理。

用法:注解类。

配合使用的注解有@Pointcut, @After, @Befor,@AfterReturning、@AfterThrowing、@AfterThrowing、@Around

例:xml配置
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"><!-- 启用AspectJ对Annotation的支持 --><aop:aspectj-autoproxy/><bean id="userManager" class="com.zlk.aspect.UserManagerImpl"/><bean id="aspcejHandler" class="com.zlk.aspect.AspceJAdvice"/></beans>1、public interface UserManager {public String findUserById(int userId);
}2.public class UserManagerImpl implements UserManager {public String findUserById(int userId) {System.out.println("---------UserManagerImpl.findUserById()--------");if (userId <= 0) {throw new IllegalArgumentException("该用户不存在!");}return "张三";}
3、@Aspect
public class AspceJAdvice {/*** Pointcut* 定义Pointcut,Pointcut的名称为aspectjMethod(),此方法没有返回值和参数* 该方法就是一个标识,不进行调用*/@Pointcut("execution(* find*(..))")private void aspectjMethod(){};/*** Before* 在核心业务执行前执行,不能阻止核心业务的调用。* @param joinPoint*/@Before("aspectjMethod()")public void beforeAdvice(JoinPoint joinPoint) {System.out.println("-----beforeAdvice().invoke-----");System.out.println(" 此处意在执行核心业务逻辑前,做一些安全性的判断等等");System.out.println(" 可通过joinPoint来获取所需要的内容");System.out.println("-----End of beforeAdvice()------");}/*** After* 核心业务逻辑退出后(包括正常执行结束和异常退出),执行此Advice* @param joinPoint*/@After(value = "aspectjMethod()")public void afterAdvice(JoinPoint joinPoint) {
//        joinPoint.getArgs();System.out.println("-----afterAdvice().invoke-----");System.out.println(" 此处意在执行核心业务逻辑之后,做一些日志记录操作等等");System.out.println(" 可通过joinPoint来获取所需要的内容");System.out.println("-----End of afterAdvice()------");}/*** Around* 手动控制调用核心业务逻辑,以及调用前和调用后的处理,** 注意:当核心业务抛异常后,立即退出,转向AfterAdvice* 执行完AfterAdvice,再转到ThrowingAdvice* @param pjp* @return* @throws Throwable*/@Around(value = "aspectjMethod()")public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable {System.out.println("-----aroundAdvice().invoke-----");System.out.println(" 此处可以做类似于Before Advice的事情");//调用核心逻辑Object retVal = pjp.proceed();System.out.println(" 此处可以做类似于After Advice的事情");System.out.println("-----End of aroundAdvice()------");return retVal;}/*** AfterReturning* 核心业务逻辑调用正常退出后,不管是否有返回值,正常退出后,均执行此Advice* @param joinPoint*/@AfterReturning(value = "aspectjMethod()", returning = "retVal")public void afterReturningAdvice(JoinPoint joinPoint, String retVal) {System.out.println("-----afterReturningAdvice().invoke-----");System.out.println("Return Value: " + retVal);System.out.println(" 此处可以对返回值做进一步处理");System.out.println(" 可通过joinPoint来获取所需要的内容");System.out.println("-----End of afterReturningAdvice()------");}/*** 核心业务逻辑调用异常退出后,执行此Advice,处理错误信息** 注意:执行顺序在Around Advice之后* @param joinPoint* @param ex*/@AfterThrowing(value = "aspectjMethod()", throwing = "ex")public void afterThrowingAdvice(JoinPoint joinPoint, Exception ex) {System.out.println("-----afterThrowingAdvice().invoke-----");System.out.println(" 错误信息:"+ex.getMessage());System.out.println(" 此处意在执行核心业务逻辑出错时,捕获异常,并可做一些日志记录操作等等");System.out.println(" 可通过joinPoint来获取所需要的内容");System.out.println("-----End of afterThrowingAdvice()------");}
}4、public class ClientTest {public static void main(String[] args) {BeanFactory factory = new ClassPathXmlApplicationContext("resources/applicationContext.xml");UserManager userManager = (UserManager)factory.getBean("userManager");//可以查找张三userManager.findUserById(1);System.out.println("=====我==是==分==割==线=====");try {// 查不到数据,会抛异常,异常会被AfterThrowingAdvice捕获userManager.findUserById(0);} catch (IllegalArgumentException e) {}}
}

1.32@EnableAspectJAutoProxy(理解不清晰)

作用:开启AspectJ 自动代理模式,如果不填proxyTargetClass=true,默认为false,

用法:@EnableAspectJAutoProxy(proxyTargetClass=true)

例:package com.dyh.ioc.base;import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;//即使用jdk默认代理模式,AspectJ代理模式是CGLIB代理模式
//如果目标对象实现了接口,默认情况下会采用JDK的动态代理实现AOP
//如果目标对象实现了接口,可以强制使用CGLIB实现AOP (此例子我们就是强制使用cglib实现aop)
//如果目标对象没有实现了接口,必须采用CGLIB库,spring会自动在JDK动态代理和CGLIB之间转换//用于定义配置类,可替换xml配置文件
@Configuration
//开启AspectJ 自动代理模式,如果不填proxyTargetClass=true,默认为false,
@EnableAspectJAutoProxy(proxyTargetClass=true)
//扫描注入类
@ComponentScan(basePackages = "com.dyh.ioc.*")
@Component
@Aspect
public class AopAspectConfiguration {//声明切入点//第一个*表示 方法  返回值(例如public int)//第二个* 表示方法的全限定名(即包名+类名)//perform表示目标方法参数括号两个.表示任意类型参数//方法表达式以“*”号开始,表明了我们不关心方法返回值的类型。然后,我们指定了全限定类名和方法名。对于方法参数列表,//我们使用两个点号(..)表明切点要选择任意的perform()方法,无论该方法的入参是什么//execution表示执行的时候触发@Pointcut("execution(* *(..))")public void point(){//该方法就是一个标识方法,为pointcut提供一个依附的地方}@Before("point()")public void before(){System.out.println("Before");}@After("point()")public void after(){System.out.println("After");}
}

1.34@Transactional

作用:事务管理,保证数据一致性。

属性: Alt text

用法:只能放在Services实现类的public方法上(放在类上可能影响性能,放接口上可能无效),只有通过action直接调用Services方法时才会回滚。

1.35 @within、@annotation、@target、@args(效果未测试出来)

@within:用于匹配所有持有指定注解类型内的方法;注解类型也必须是全限定类型名。

@target:用于匹配当前目标对象类型的执行方法,其中目标对象持有指定的注解;注解类型也必须是全限定类型名。

@args:用于匹配当前执行的方法传入的参数持有指定注解的执行;注解类型也必须是全限定类型名。

@annotation:用于匹配当前执行方法持有指定注解的方法;

1.36@Configurable

作用:用于Bean的自动装配(xml配置时,bean中可以省略id(此条测试,未通过))

注:new 对象的时候就会自动帮你装配,而不需要用BeanFactory去获取(未测试)

用法:注解类,@Configurable或者@Configurable("类名"),在xml中配置 </bean id="account" class="com.zlk.configurable.Account" scope="prototype"/> </bean/>

例:xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><!-- 启用AspectJ对Annotation的支持 --><!--   <context:spring-configured/><context:component-scan base-package="com.zlk.configurable"/><aop:aspectj-autoproxy/>--><!--<bean class="com.zlk.configurable.Account" scope="prototype"><property name="fundsTransferService" ref="fundsTransferService"/></bean>--><bean id="account" class="com.zlk.configurable.Account" scope="prototype"></bean>
</beans>1、@Configurable
//@Configurable("account")
public class Account {public Account() {System.out.println("Account 对象为" + "Account");}public void show(){System.out.println("---Account--");}
}2、public class Test {public static void main(String[] args) {//加载applicationContext.xmlClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("resources/configurable.xml");//获取实例Account account =(Account) context.getBean("account");account.show();}
}

1.37@NonNull、@NonNullApi、@NonNullFields、@Nullable(包未导成功,未测试)

作用:

@NonNull注释在特定参数,返回值或字段不能 null(不需要参数和返回值 @NonNullApi和 @NonNullFields应用)。

@Nullable注释在特定参数,返回值或字段 null.

@NonNullApi注释在包级别声明非空参数和返回值的默认行为。

@NonNullFields注释在包级别声明非空字段的默认行为。

用法:

2、测试

2.1@BootstrapWith(理解模糊)

作用:@BootstrapWith是一个类级别注释,用于配置Spring和TestContext框架是如何引导的。具体地说, @BootstrapWith用于指定一个自定义 TestContextBootstrapper。 用法:注解类、接口

2.2@ContextConfiguration

作用:用于确认如何加载和配置一个ApplicationContext集成测试,

@ContextConfiguration声明应用程序上下文资源 locations或注释 classes将用于加载上下文。 用法:注解类。

例:加载配置文件(如1)或者配置类(如2),若是多个配置文件用逗号隔开。
1、@ContextConfiguration(Locations="../applicationContext.xml")  
public class XmlApplicationContextTests {// class body...
}2、@ContextConfiguration(classes = SimpleConfiguration.class)
public class XmlApplicationContextTests {// class body...
}

2.3@WebAppConfiguration(未完成测试,报错)

作用:与@ContextConfiguration一起使用,使用的默认值 "file:src/main/webapp"对web应用程序的根的路径(即。资源基础的路径)。在幕后使用的资源基础路径创建一个 MockServletContext这是 ServletContext测试的 WebApplicationContext.

用法:注解测试类,

属性:classpath:和 file @WebAppConfiguration("src/test/webapp") @WebAppConfiguration("classpath:test-web-resources")

例:@RunWith(SpringJUnit4ClassRunner.class)//指定单元测试类
// @WebAppConfiguration omitted on purpose
@ContextConfiguration(classes = WebConfig.class)//配置文件或者配置类
public class EmployeeTest {@Autowiredprivate WebApplicationContext webAppContext;private MockMvc mockMvc;@Beforepublic void setup() {MockitoAnnotations.initMocks(this);mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext).build();}...
}

2.4@ContextHierarchy(未测试)

例:@RunWith(SpringRunner.class)
@ContextHierarchy({@ContextConfiguration(name = "parent", locations = "/app-config.xml"),@ContextConfiguration(name = "child", locations = "/user-config.xml")
})
public class BaseTests {}@ContextHierarchy(@ContextConfiguration(name = "child",locations = "/test-user-config.xml",inheritLocations = false
))
public class ExtendedTests extends BaseTests {}

2.5@RunWith

作用:用于指明单元测试类。

用法:注解单元测试类。例子见2.3。

2.6@TestExecutionListeners(未测试)

作用:用于指定在测试类执行之前,可以做的一些动作,如这里的>DependencyInjectionTestExecutionListener.class,就可以对一测试类中的依赖进行注入,>TransactionalTestExecutionListener.class用于对事务进行管理;这两个都是Srping自带的; 我们也可以实现自>己的Listener类来完成我们自己的操作,只需要继续类 org.springframework.test.context.support.AbstractTestExecutionListener

用法:注解类。

例:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:/spring1.xml", "classpath*:/spring2.xml" })
@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class })
@Transactional
public class TestClass {@Inject//这个类会在执行时被注入,这里是按类型注入,如果想按名称注入,需要加上@Named注解,如@Named("class1")//实现类可以加上@Named("class1")注解,也可以是配置在配置文件中的Class1 class1;
    @Test public void  t1(){}

2.7@Transactional

作用:和@TestExecutionListeners中的 TestExecutionListener.class配合使用,用于保证插入的>数据库中的测试数据,在测试完后,事务自动回滚,将插入的数据给删除掉,保证数据库的干净。(此处是针对测试类的用法,不是业务层)

注:可以使用@Commit 、 @Rollback控制提交和回滚(@Rollback(false)不回滚,@Rollback(true)回滚)。 @BeforeTransaction注解事务执行前的方法,@AfterTransaction注解事务执行后的方法;另有@Sql、@SqlGroup、@SqlConfig

用法:注解方法、接口、类(例见2.6)

2.8@IfProfileValue(理解模糊)

作用:(不明) 用法:注解类

例:只附测试类(结果Test ignored,原因不明)
@RunWith(SpringJUnit4ClassRunner.class)//表示整合JUnit4进行测试
//@ComponentScan("com.zlk.within"),报错
@IfProfileValue(name="java.vendor", value="com zlk within.")
@ContextConfiguration(locations={"classpath:spring-config.xml"})//加载spring配置文件
public class IfProfileValueTest {@Resourceprivate Member member;@Resourceprivate Leader leader;// 实现@Testpublic void test1() {System.out.println("---------------member---------------");member.who();System.out.println("---------------leader---------------");leader.who();}
}

2.9@ProfileValueSourceConfiguration(不理解)

作用:类级别注解用来指定当通过@IfProfileValue注解获取已配置的profile值时使用何种ProfileValueSource。 如果@ProfileValueSourceConfiguration没有在测试中声明,将默认使用 SystemProfileValueSource。

2.10@Timed

作用:测试方法必须在执行时间内完成(毫秒),否则会报错,测试失败。 用法:注解方法或注解上。配合@Test使用

例:@Test@Timed(millis = 1000)public void test2() {System.out.println("---------------member---------------");member.who();System.out.println("---------------leader---------------");leader.who();}

2.11@Repeat

作用:控制测试方法执行次数。 用法:@Repeat(执行次数)

 例:@Repeat(5)@Testpublic void test3() {System.out.println("执行一次");}

2.12@SpringJUnitConfig、@SpringJUnitWebConfig(未测试)

作用:组合注解,用于加载配置

2.13@EnabledIf(未测试)

作用:@EnabledIf条件满足允许执行,@DisabledIf条件满足禁止执行。

例:1、@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@EnabledIf(expression = "#{systemProperties['os.name'].toLowerCase().contains('mac')}",reason = "Enabled on Mac OS"
)
public@interface EnabledOnMac {}2、@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@DisabledIf(expression = "#{systemProperties['os.name'].toLowerCase().contains('mac')}",reason = "Disabled on Mac OS"
)
public@interface DisabledOnMac {}

2.13@ResponseBody [Response [rɪˈspɒns]响应]

作用:@Responsebody 注解表示该方法的返回的结果直接写入 HTTP 响应正文(ResponseBody)中,一般在异步获取 数据时使用,通常是在使用 @RequestMapping 后,返回值通常解析为跳转路径,加上 @Responsebody 后返回结果不 会被解析为跳转路径,而是直接写入HTTP 响应正文中。

例:
@RequestMapping(value = "user/login/{id}/{name}/{status}")
@ResponseBody
public User login(@PathVariable int id, @PathVariable String name, @PathVariable boolean status) {
//返回一个User对象响应ajax的请求return new User(id, name, status);
}

2.14@DirtiesContext

3、数据访问(Data Access)

3.1@Transactional

作用:做事务管理

用法:注解类、接口、方法(推荐)

属性:Alt text

例:@Transactional(readOnly = true)
public class DefaultFooService implements FooService {public Foo getFoo(String fooName) {// do something}// these settings have precedence for this method@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)public void updateFoo(Foo foo) {// do something}
}

3.2@EnableTransactionManagement(spring Boot注解)

用于启动注解事务管理。

例@EnableTransactionManagement // 启注解事务管理,等同于xml配置方式的 <tx:annotation-driven />
@SpringBootApplication
public class ProfiledemoApplication {@Beanpublic Object testBean(PlatformTransactionManager platformTransactionManager){System.out.println(">>>>>>>>>>" + platformTransactionManager.getClass().getName());return new Object();}public static void main(String[] args) {SpringApplication.run(ProfiledemoApplication.class, args);}
}

3.3@EventListener

3.4@TransactionalEventListener

作用:注解模型与发布事件

用法:需要管理的bean的公共方法使用@EventListener 注解来消费事件。 @TransactionalEventListener 提供事务绑定事件支持。

3.5@Repository

作用:让spring创建相应实例。(用于dao层)

用法:注解类。@Repository(value="userDao")或者@Repository

例: @Repository public class UserDao { … } 

3.6@PersistenceContext、@PersistenceUnit(两个都是jpa注解)

作用:@PersistenceContext注入的是实体管理器,执行持久化操作的,需要配置文件persistence.xml。 @PersistenceUnit

3.7@EnableLoadTimeWeaving

作用:做时间监控(不明白) 用法:注解类,配合@Configuration使用。

例:
@Configuration@EnableLoadTimeWeavingpublic class AppConfig {// application-specific @Bean definitions ...}

4、Web Servlet

4.1@RequestMapping、@GetMapping、@PostMapping、@PutMapping、@DeleteMapping、@PatchMapping

作用:@RequestMapping处理请求地址映射。后面注解等同于@RequestMapping加method属性时的效果。

@RequestMapping属性:(参考https://www.cnblogs.com/qq78292959/p/3760560.html)

value:指定请求的实际地址。

method: 指定请求的method类型, GET、POST、PUT、DELETE等。

consumes: 指定处理请求的提交内容类型(Content-Type),例如application/json, text/html。

produces: 指定返回的内容类型,仅当request请求头中的(Accept)类型中包含该指定类型才返回。

params: 指定request中必须包含某些参数值是,才让该方法处理。

headers: 指定request中必须包含某些指定的header值,才能让该方法处理请求。

用法:@RequestMapping注解类(类上面的地址作为父路径)和方法。

例:@RestController
@RequestMapping("/hello")
public class HelloController {@RequestMapping(value="/hsay",method= RequestMethod.GET)public String sayHello(@PathVariable("id") Integer id){return "id:"+id;}
}

4.2@ExceptionHandler

作用:统一处理某一类的异常,减少代码重复率。(参考https://blog.csdn.net/liujia120103/article/details/75126124)

用法:注解方法。

4.3@ControllerAdvice

作用:全局异常管理(spring能扫描到的类,就可以实现该异常处理)

用法:注解异常管理类,配合@ExceptionHandler使用

4.4@ResponseStatu

作用:用于自定义异常,可配合@ExceptionHandler使用(参考https://blog.csdn.net/lovesomnus/article/details/73188823)

用法:注解类

4.5@ResponseBody

作用:将方法的返回的结果直接写入 HTTP 响应正文(ResponseBody)中,一般在异步获取数据时使用,通常是在使用 @RequestMapping 后,返回值通常解析为跳转路径,加上 @Responsebody 后返回结果不会被解析为跳转路径,而是直接写入HTTP 响应正文中。(一般返回数据json或者xml时使用)。

注:(前台提交时)
A) GET、POST方式提时, 根据request header Content-Type的值来判断:application/x-www-form-urlencoded, 可选(即非必须,因为这种情况的数据@RequestParam, @ModelAttribute也可以处理,当然@RequestBody也能处理);multipart/form-data, 不能处理(即使用@RequestBody不能处理这种格式的数据);其他格式, 必须(其他格式包括application/json, application/xml等。这些格式的数据,必须使用@RequestBody来处理);
B) PUT方式提交时, 根据request header Content-Type的值来判断:application/x-www-form-urlencoded, 必须;multipart/form-data, 不能处理;其他格式, 必须;

说明:request的body部分的数据编码格式由header部分的Content-Type指定;

用法:注解方法,一般配合@RequestMapping使用。

例:@RequestMapping(value = "user/login")
@ResponseBody
// 将ajax(datas)发出的请求写入 User 对象中,返回json对象响应回去
public User login(User user) {   User user = new User();user .setUserid(1);return user ;
}

4.6@Controller

作用:使用该注解后,spring容器会对齐生成一个对应Bean(首字母小写)命名的action。配合@RequestMapping使用时将定位到页面。配合@ResponseBody使用时可返回json数据。 用法:注解类。(Controller层)

例:
1、 @Controller
//或@Controller(value="UserAction") 或@Controller("UserAction")public class UserAction{@RequestMapping(value = "user/login")// 将ajax(datas)发出的请求写入 User 对象中,返回json对象响应回去public String login(User user) {   return "/views/index";}}2、@Controllerpublic class UserAction{@RequestMapping(value = "user/login")@ResponseBody// 将ajax(datas)发出的请求写入 User 对象中,返回json对象响应回去public User login(User user) {   User user = new User();user .setUserid(1);return user ;}}

4.7@RestController

作用:@Controller与@ResponseBody组合而成,其返回时将不定位页面,而是直接返回数据。 需要定位页面需要使用modelandview类。 用法:注解controller类。

例:1、@RestControllerpublic class UserAction{@RequestMapping(value = "user/login")// 将ajax(datas)发出的请求写入 User 对象中,返回json对象响应回去public User login(User user) {   User user = new User();user .setUserid(1);return user ;}}2、@RestControllerpublic class UserAction{@RequestMapping(value = "user/login")// 将ajax(datas)发出的请求写入 User 对象中,返回json对象响应回去public ModelAndView login(User user) {   return new  ModelAndView("/views/index.html");}}

4.8@PathVariable

作用:用于获取参数。(需要占位,前后端参数位置要对应) 用法:注解形参。

例:@RequestMapping("/edit/{id}/{name}") public String edit(Model model, @PathVariable long id,@PathVariable String name) {

    return page("edit");
}

4.9@RequestParam

作用:用于获取参数。

属性:

value:参数名字,即入参的请求参数名字,如username表示请求的参数区中的名字为username的参数的值将传入;

required:是否必须,默认是true,表示请求中一定要有相应的参数,否则将报404错误码;

defaultValue:默认值,表示如果请求中没有同名参数时的默认值

用法:注解形参。void method(@RequestParam String name) 或void method(@RequestParam("name") String name);

例: @Controller @RequestMapping("/wx") public class WxController {

  @Autowiredprivate WxService wxService;private static final Log log= LogFactory.getLog(WxController.class);@RequestMapping(value = "/service",method = RequestMethod.GET)public void acceptWxValid(@RequestParam String signature, @RequestParam String timestampthrows IOException {}

4.10@RequestHeader

作用:可以把Request请求header部分的值绑定到方法的参数上。 用法:注解形参。

例:这是一个Request 的header部分:[plain] view plaincopy
Host                    localhost:8080  
Accept                  text/html,application/xhtml+xml,application/xml;q=0.9  
Accept-Language         fr,en-gb;q=0.7,en;q=0.3  
Accept-Encoding         gzip,deflate  
Accept-Charset          ISO-8859-1,utf-8;q=0.7,*;q=0.7  
Keep-Alive              300  [java] view plaincopy
@RequestMapping(“/displayHeaderInfo.do”)  
public void displayHeaderInfo(@RequestHeader(“Accept-Encoding”) String encoding,  @RequestHeader(“Keep-Alive”) long keepAlive)  {  //…  }  
上面的代码,把request header部分的 Accept-Encoding的值,绑定到参数encoding上了, Keep-Alive header的值绑定到参数keepAlive上。

4.11@MatrixVariable

作用:获取URL上对应名称的值。 用法:注解形参。

例:1、// GET /pets/42;q=11;r=22@GetMapping("/pets/{petId}")
public void findPet(@PathVariable String petId, @MatrixVariable int q) {// petId == 42// q == 11
}2、// GET /owners/42;q=11/pets/21;q=22@GetMapping("/owners/{ownerId}/pets/{petId}")
public void findPet(@MatrixVariable(name="q", pathVar="ownerId") int q1,@MatrixVariable(name="q", pathVar="petId") int q2) {// q1 == 11// q2 == 22
}

4.12@CookieValue

作用:获取cookie的值。

属性

(1) value 请求参数的参数名;

(2) required 该参数是否必填,默认为true(必填),当设置成必填时,如果没有传入参数,报错;

(3) defaultValue 设置请求参数的默认值;

用法:注解形参。

例:
@RequestMapping("/springmvc")
@Controller
public class HelloWorld {
@RequestMapping("/testCookieValue")public String testCookieValue(@CookieValue("JSESSIONID")String sessionId){System.out.println("testCookieValue: "+sessionId);return "success";}

4.13@RequestPart

作用:@RequestPart 绑定“multipart/data”数据,除了能绑定@RequestParam 能做到的请求参数外,还能绑定上传的文件等 用法:与@RequestParam相似。注解形参。

4.14@ModelAttribute

作用:注解方法时,controller中被@ModelAttribute注解的方法会先执行,后执行请求方法。 注解形参时,如注解@ModelAttribute("user"),用于获取参,user类必须有无参构造。 用法:绑定形参或者无返回值的方法。

例:1、@ModelAttribute
public String test1(UserModel user) 2、public String test1(@ModelAttribute("user") UserModel user)   

4.15@SessionAttribute

作用:让参数在多个请求间共享 用法:注解类。

例:@Controller
@RequestMapping("sc")
@SessionAttributes("name")
public class SessionController {@RequestMapping("session")public String sessions(Model model,HttpSession session){model.addAttribute("name", "winclpt");session.setAttribute("myName", "chke");return "session";
}上面的代码将Model中的name参数保存到了session中(如果Model中没有name参数,而session中存在一个name参数,那么SessionAttribute会讲这个参数塞进Model中)SessionAttribute有两个参数:String[] value:要保存到session中的参数名称Class[] typtes:要保存的参数的类型,和value中顺序要对应上所以可以这样写:@SessionAttributes(types = {User.class,Dept.class},value={“attr1”,”attr2”})原理理解:它的做法大概可以理解为将Model中的被注解的attrName属性保存在一个SessionAttributesHandler中,在每个RequestMapping的方法执行后,这个SessionAttributesHandler都会将它自己管理的“属性”从Model中写入到真正的HttpSession;同样,在每个RequestMapping的方法执行前,SessionAttributesHandler会将HttpSession中的被@SessionAttributes注解的属性写入到新的Model中。如果想删除session中共享的参数,可以通过SessionStatus.setComplete(),这句只会删除通过@SessionAttribute保存到session中的参数

4.16@SessionAttributes

作用:@SessionAttributes注解就可以使得模型中的数据存储一份到session域中。

属性: 1、names:这是一个字符串数组。里面应写需要存储到session中数据的名称。

2、types:根据指定参数的类型,将模型中对应类型的参数存储到session中

value:其实和names是一样的。

例:@SessionAttributes(value={"names"},types={Integer.class})@Controllerpublic class Test {@RequestMapping("/test")public String test(Map<String,Object> map){map.put("names", Arrays.asList("caoyc","zhh","cjx"));map.put("age", 18);return "hello";}}JSP
request中names:${requestScope.names}<br/>
request中age:${requestScope.age}<br/>
<hr/>
session中names:${sessionScope.names }<br/>
session中age:${sessionScope.age }<br/>

4.17@RequestAttribute

作用:可以被用于访问由过滤器或拦截器创建的、预先存在的请求属性(不明白)

用法:注解形参。

例:1、 @RequestMapping("/reqAttr")public String handle(@RequestAttribute("reqStr") String str, Model model){System.out.println("--> reqStr : " + str);model.addAttribute("sth", str);return "/examples/targets/test1";}2、@WebFilter(filterName = "myFilter", description = "测试过滤器", urlPatterns = { "/*" })
public class MyFilter implements Filter
{@Overridepublic void init(FilterConfig filterConfig) throws ServletException{}@Overridepublic void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException{System.out.println("--> MyFilter Do.");request.setAttribute("reqStr", "万万没想到,啦啦啦啦啦!");chain.doFilter(request, response);}@Overridepublic void destroy(){}}

4.18 @JsonView

作用:@JsonView注解用来过滤序列化对象的字段属性,转换json.

用法:注解属性字段或者方法。

例:public class View {public interface Summary {}public interface SummaryWithDetail extends Summary{}
}public class User { @JsonView(View.Summary.class) private Long id; @JsonView(View.Summary.class) private String firstname; @JsonView(View.Summary.class) private String lastname; @JsonView(View.SummaryWithDetail .class) private String email; @JsonView(View.SummaryWithDetail .class) private String address; private String postalCode; private String city; private String country;...
}@RestController
public class UserRestController{@Autowired private UserService userService;@RequestMapping("/user")@JsonView(View.Summary.class) public List<User> getUsers(){return userService.listUsers();}@RequestMapping("/userWithDetail")@JsonView(View.SummaryWithDetail.class) public List<User> getUsersWithDetail(){return userService.listUsers();}
}

4.19@InitBinder

作用:表单多对象精准绑定。

用法:注解形参。

例:
<form action="/test/test" method="post">  <input type="text" name="user.id" value="huo_user_id">  <input type="text" name="user.name" value="huo_user_name">  <input type="text" name="addr.id" value="huo_addr_id">  <input type="text" name="addr.name" value="huo_addr_name">  <input type="submit" value="提交">  
</form>  @Controller  
@RequestMapping("/test")  
public class TestController {  
// 绑定变量名字和属性,参数封装进类  @InitBinder("user")  public void initBinderUser(WebDataBinder binder) {  binder.setFieldDefaultPrefix("user.");  }  // 绑定变量名字和属性,参数封装进类  @InitBinder("addr")  public void initBinderAddr(WebDataBinder binder) {  binder.setFieldDefaultPrefix("addr.");  }     @RequestMapping("/test")  @ResponseBody  public Map<String,Object> test(HttpServletRequest request,@ModelAttribute("user") User user,@ModelAttribute("addr") Addr addr){  Map<String,Object> map=new HashMap<String,Object>();  map.put("user", user);  map.put("addr", addr);  return map;  }  

4.20@CrossOrigin

作用:用于实现跨域访问。

用法:注解类或者方法。

例:
@CrossOrigin()
@RestController
@RequestMapping("/test")
public class TestController {@RequestMapping("/{id}")public Account retrieve(@PathVariable Long id) {// ...}@RequestMapping(method = RequestMethod.DELETE, path = "/{id}")public void remove(@PathVariable Long id) {// ...}

4.21@EnableWebMvc

作用:用于启用MVC Java config。相当于xml中的<mvc:annotation-driven> 。

用法:注解类,配合@Configuration使用。

例:@Configuration
@EnableWebMvc
public class WebConfig {
}

5、Web Reactive

5.1@Validated、@Valid

作用:用于校验bean中相关注解标注的属性值。

注:可使用@Validated校验的bean属性注解有: @Null 限制只能为null

@NotNull 限制必须不为null

@AssertFalse 限制必须为false

@AssertTrue 限制必须为true

@DecimalMax(value) 限制必须为一个不大于指定值的数字

@DecimalMin(value) 限制必须为一个不小于指定值的数字

@Digits(integer,fraction) 限制必须为一个小数,且整数部分的位数不能超过integer,小数部分的位数不能超过fraction

@Future 限制必须是一个将来的日期

@Max(value) 限制必须为一个不大于指定值的数字

@Min(value) 限制必须为一个不小于指定值的数字

@Past 验证注解的元素值(日期类型)比当前时间早

@Pattern(value) 限制必须符合指定的正则表达式

@Size(max,min) 限制字符长度必须在min到max之间

@NotEmpty 验证注解的元素值不为null且不为空(字符串长度不为0、集合大小不为0)

@NotBlank 验证注解的元素值不为空(不为null、去除首位空格后长度为0),不同于@NotEmpty,@NotBlank只应用于字符串且在比较时会去除字符串的空格

@Email 验证注解的元素值是Email,也可以通过正则表达式和flag指定自定义的email格式

用法:注解形参。

例:
public class User {  private String id; @NotEmpty(message = "{edit.username.null}")private String username;@Size(min=6 ,max= 20 ,message = "{edit.password.size}")private String password;......
}@Controller  
public class UserController {  @RequestMapping("/save")  public String save(@Validated User user, BindingResult result) {  if(result.hasErrors()) {  return "error";  }  return "success";  }  
}

5.2@EnableWebFlux

6、Integration

6.1@WebService

作用:实现远程调用。

属性:

1、serviceName: 对外发布的服务名,指定 Web Service 的服务名称:wsdl:service。缺省值为 Java 类的简单名称 + Service。(字符串)

2、endpointInterface: 服务接口全路径, 指定做SEI(Service EndPoint Interface)服务端点接口

3、name:此属性的值包含XML Web Service的名称。在默认情况下,该值是实现XML Web Service的类的名称,wsdl:portType 的名称。缺省值为 Java 类的简单名称 + Service。(字符串)

4、portName: wsdl:portName。缺省值为 WebService.name+Port。

5、targetNamespace:指定你想要的名称空间,认是使用接口实现类的包名的反缀

6、wsdlLocation:指定用于定义 Web Service 的 WSDL 文档的 Web 地址。Web 地址可以是相对路径或绝对路径。(字符串)

注意:实现类上可以不添加Webservice注解

用法:注解类。

例: /** * 将 Java 类标记为实现 Web Service,或者将 Java 接口标记为定义 Web Service 接口 * @author * */ //修改目标空间 ,修改服务名 在wsdl那里的xml文件显示对应的修改信息 @WebService(targetNamespace="http://www.itcast.cn",serviceName="MyService") public class HelloService { //修改方法名 返回值的名字 @WebMethod(operationName="hello") @WebResult(name="ret") public String sayHello( //修改参数名字 @WebParam(name="name") String name, @WebParam(name="age") int age){ System.out.println("sayHello called..."); return "hello " + name; } //此方法 本系统测试 不对外发布 @WebMethod(exclude=true) public String sayHello2(String name){ System.out.println("sayHello called..."); return "hello " + name; }

    public static void main(String[] args) {//参数1:绑定服务的地址   参数2:提供服务的实例Endpoint.publish("http://192.168.1.101:5678/hello", new HelloService());System.out.println("server ready...");}
}

6.2@WebMethod

作用:注释表示作为一项 Web Service 操作的方法,将此注释应用于客户机或服务器服务端点接口(SEI)上的方法,或者应用于 JavaBeans 端点的服务器端点实现类。(用于向外公布,它修饰的方法是webservice方法)。

属性:要点: 仅支持在使用 @WebService 注释来注释的类上使用 @WebMethod 注释

1、operationName:指定与此方法相匹配的wsdl:operation 的名称。缺省值为 Java 方法的名称。(字符串)

2、action:定义此操作的行为。对于 SOAP 绑定,此值将确定 SOAPAction 头的值。缺省值为 Java 方法的名称。(字符串)

3、exclude:指定是否从 Web Service 中排除某一方法。缺省值为 false。(布尔值)

用法:注解到@WebService注解类的方法上。

6.3@SOAPBinding

6.4@JmsListener

作用:异步接收消息,@JmsListener公开的bean公开一个JMS侦听器端点。(参考:http://websystique.com/spring/spring-4-jms-activemq-example-with-jmslistener-enablejms/)

用法:注解方法。

例:@Component publicc lassMyService {

@JmsListener(destination = "myDestination")
public void processOrder(String data) { ... }

}

6.5@EnableJms

作用:创建消息侦听容器。

用法:注解类,配合@Configuration使用。

例:@Configuration @EnableJms public class AppConfig { @Bean public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() { DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); factory.setConnectionFactory(connectionFactory()); factory.setDestinationResolver(destinationResolver()); factory.setSessionTransacted(true); factory.setConcurrency("3-10"); return factory; } }

6.6@Header、@Headers

作用:@Header带注释的方法参数中提取特定头值,包括标准JMS标头。 @Headers-注解参数为了访问所有头信息,必须能指定为java.util.Map.

用法:注解形参

例:@ComponentpublicclassMyService {@JmsListener(destination = "myDestination")public void processOrder(Order order, @Header("order_type") String orderType) {...}
}

6.7@SendTo

作用:会将接收到的消息发送到指定的路由目的地,所有订阅该消息的用户都能收到,属于广播。

用法:注解方法。

例:@JmsListener(destination = "myDestination")@SendTo("status")public Message<OrderStatus> processOrder(Order order) {// order processingreturn MessageBuilder.withPayload(status).setHeader("code", 1234).build();}

6.8@Payload

6.9@ManagedResource

作用:将类的所有实例标识为JMX受控资源(参考:https://blog.csdn.net/yaerfeng/article/details/28232435)

用法:注解类。

例:

6.10@ManagedAttribute

作用:将方法标识为JMX操作

用法:注解方法。(例见6.9)

6.11@ManagedOperation

作用:将getter或者setter标识为部分JMX属性

用法:注解get与set方法。(例见6.9)

6.12 @ManagedOperationParameters、@ManagedOperationParameter

作用:定义操作说明。

用法:注解方法。(例见6.9)

6.13@EnableMBeanExport

作用:在javaconfig类中开启注解,相当与<context:mbean-export/>

用法:注解类。

例:@EnableMBeanExport(server="myMBeanServer", defaultDomain="myDomain")
//相当于<context:mbean-exportserver="myMBeanServer"default-domain="myDomain"/>
@Configuration
ContextConfiguration {}

6.14@EnableAsync

作用:@EnableAsync配合@Async异步执行。(参考:https://blog.csdn.net/u010502101/article/details/78759786)

用法:注解类。

例:@Component
public class CountNumber {@Asyncpublic void PrintNumber(){for(int i=1; i<10; i++){System.out.println("i = " + i);}}
}/*@SpringBootApplication注解与@ComponentScan、@EnableAsync注解达到相同的功效*/
//@SpringBootApplication
@ComponentScan
@EnableAsync
public class Springboot3Application {public static void main(String[] args) throws Exception {ConfigurableApplicationContext context = SpringApplication.run(Springboot3Application.class, args);/*@Async和@EnableAsync配合使用*/context.getBean(CountNumber.class).PrintNumber();for(int i=1; i<10; i++){TimeUnit.MICROSECONDS.sleep(1);System.out.println("------------------");}context.close();}
}

6.15@Scheduled、@EnableScheduling

作用:定时任务在配置类上添加@EnableScheduling开启对定时任务的支持,在相应的方法上添加@Scheduled声明需要执行的定时任务。

@Scheduled属性参数:
1、cron
2、zone
3、fixedDelay和fixedDelayString
4、fixedRate和fixedRateString
5、initialDelay和initialDelayString注:1.cron是设置定时执行的表达式,如 0 0/5 * * * ?每隔五分钟执行一次2.zone表示执行时间的时区3.fixedDelay 和fixedDelayString 表示一个固定延迟时间执行,上个任务完成后,延迟多长时间执行4.fixedRate 和fixedRateString表示一个固定频率执行,上个任务开始后,多长时间后开始执行5.initialDelay 和initialDelayString表示一个初始延迟时间,第一次被调用前延迟的时间

用法:@EnableScheduling注解配置类,@Scheduled注解方法。

例:1、@Configuration
@ComponentScan({"com.xingguo.logistics.service.aspect")
@EnableScheduling
public class AopConfig{
}2、@Service
public class TestService2 {private static final SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");//初始延迟1秒,每隔2秒@Scheduled(fixedRateString = "2000",initialDelay = 1000)public void testFixedRate(){System.out.println("fixedRateString,当前时间:" +format.format(new Date()));}//每次执行完延迟2秒@Scheduled(fixedDelayString= "2000")public void testFixedDelay(){System.out.println("fixedDelayString,当前时间:" +format.format(new Date()));}//每隔3秒执行一次@Scheduled(cron="0/3 * * * * ?")public void testCron(){System.out.println("cron,当前时间:" +format.format(new Date()));}
}3、public class TestController {public static void main(String[] args) {AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AopConfig.class);}
}

6.16@Cacheable

作用:(参考:https://www.cnblogs.com/fashflying/p/6908028.html) @Cacheable可以标记在一个方法上,也可以标记在一个类上。当标记在一个方法上时表示该方法是支持缓存的,当标记在一个类上时则表示该类所有的方法都是支持缓存的。对于一个支持缓存的方法,Spring会在其被调用后将其返回值缓存起来,以保证下次利用同样的参数来执行该方法时可以直接从缓存中获取结果,而不需要再次执行该方法。Spring在缓存方法的返回值时是以键值对进行缓存的,值就是方法的返回结果,至于键的话,Spring又支持两种策略,默认策略和自定义策略,这个稍后会进行说明。需要注意的是当一个支持缓存的方法在对象内部被调用时是不会触发缓存功能的。@Cacheable可以指定三个属性,value、key和condition。

属性:

value属性是必须指定的,其表示当前方法的返回值是会被缓存在哪个Cache上的,对应Cache的名称.

key属性是用来指定Spring缓存方法的返回结果时对应的key的。该属性支持SpringEL表达式。当我们没有指定该属性时,Spring将使用默认策略生成key。Spring还为我们提供了一个root对象可以用来生成key。

有的时候我们可能并不希望缓存一个方法所有的返回结果。通过condition属性可以实现这一功能。condition属性默认为空,表示将缓存所有的调用情形。其值是通过SpringEL表达式来指定的,当为true时表示进行缓存处理;当为false时表示不进行缓存处理,即每次调用该方法时该方法都会执行一次。

用法:注解类、方法。

例:1、@Cacheable({"cache1", "cache2"})//Cache是发生在cache1和cache2上的public User find(Integer id) {returnnull;}2、 @Cacheable(value="users", key="#id")public User find(Integer id) {returnnull;}3、 @Cacheable(value={"users", "xxx"}, key="caches[1].name")public User find(User user) {returnnull;}4、 @Cacheable(value={"users"}, key="#user.id", condition="#user.id%2==0")public User find(User user) {System.out.println("find user by user " + user);return user;}

6.17@CacheEvict

作用:@CacheEvict是用来标注在需要清除缓存元素的方法或类上的。当标记在一个类上时表示其中所有的方法的执行都会触发缓存的清除操作。@CacheEvict可以指定的属性有value、key、condition、allEntries和beforeInvocation。其中value、key和condition的语义与@Cacheable对应的属性类似。即value表示清除操作是发生在哪些Cache上的(对应Cache的名称);key表示需要清除的是哪个key,如未指定则会使用默认策略生成的key;condition表示清除操作发生的条件。下面我们来介绍一下新出现的两个属性allEntries和beforeInvocation。(见例:)

用法:注解方法、类。

例:
1、allEntries属性allEntries是boolean类型,表示是否需要清除缓存中的所有元素。默认为false,表示不需要。当指定了allEntries为true时,Spring Cache将忽略指定的key。有的时候我们需要Cache一下清除所有的元素,这比一个一个清除元素更有效率。@CacheEvict(value="users", allEntries=true)public void delete(Integer id) {System.out.println("delete user by id: " + id);}2、 beforeInvocation属性清除操作默认是在对应方法成功执行之后触发的,即方法如果因为抛出异常而未能成功返回时也不会触发清除操作。使用beforeInvocation可以改变触发清除操作的时间,当我们指定该属性值为true时,Spring会在调用该方法之前清除缓存中的指定元素。@CacheEvict(value="users", beforeInvocation=true)public void delete(Integer id) {System.out.println("delete user by id: " + id);}

6.18@CachePut

作用:与@Cacheable不同的是使用@CachePut标注的方法在执行前不会去检查缓存中是否存在之前执行过的结果,而是每次都会执行该方法,并将执行结果以键值对的形式存入指定的缓存中。属性和@Cacheable相同。

用法:注解方法、类。

例:// @CachePut也可以标注在类上和方法上。使用@CachePut时我们可以指定的属性跟@Cacheable是一样的。@CachePut("users")//每次都会执行方法,并将结果存入指定的缓存中public User find(Integer id) {returnnull;}

6.19@Caching

作用:@Caching注解可以让我们在一个方法或者类上同时指定多个Spring Cache相关的注解。其拥有三个属性:cacheable、put和evict,分别用于指定@Cacheable、@CachePut和@CacheEvict。

用法:注解方法、类。

例:@Caching(cacheable = @Cacheable("users"), evict = { @CacheEvict("cache2"),@CacheEvict(value = "cache3", allEntries = true) })public User find(Integer id) {returnnull;}

6.20@CacheConfig

作用:有时候一个类中可能会有多个缓存操作,而这些缓存操作可能是重复的。这个时候可以使用@CacheConfig。

用法:@CacheConfig是一个类级别的注解,允许共享缓存的名称、KeyGenerator、CacheManager 和CacheResolver。 该操作会被覆盖。

例:@CacheConfig("books")
public class BookRepositoryImpl implements BookRepository {@Cacheablepublic Book findBook(ISBN isbn) {...}
}#### 开启缓存注解
java类配置:
@Configuration
@EnableCaching
public class AppConfig {
}XML 配置:
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:cache="http://www.springframework.org/schema/cache"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"><cache:annotation-driven /></beans>

6.21 @CacheKey

作用:该注解用来在请求命令的参数上标记,使其作为缓存的Key值,如果没有标注则会使用所有参数。如果同事还是使用了@CacheResult和@CacheRemove注解的cacheKeyMethod方法指定缓存Key的生成,那么该注解将不会起作用。属性value。

用法:注解形参。

例:
@Service
public class CacheKeyDemo2 {@Autowiredprivate RestTemplate restTemplate;@HystrixCommand(fallbackMethod = "hiConsumerFallBack")public User hiConsumer(@CacheKey("id") User user) {//SERVICE_HI是服务端的spring.application.name,并且大写,hi为服务端提供的接口return restTemplate.getForEntity("http://SERVICE_HI/hi", User.class, user.getId()).getBody();}public String hiConsumerFallBack(String id, Throwable e) {return "This is a error";}}

7、Languages

7.1@field

7.2@get

7.3@LocalServerPort

作用:通过 @LocalServerPort注解,获取测试时动态的端口号。

用法:

例:@RunWith(SpringRunner.class)
@SpringBootTest(classes = ServerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class Test {@LocalServerPortprivate int port;private URL base;private Gson gson = new Gson();@Autowiredprivate TestRestTemplate restTemplate;@Beforepublic void setUp() throws Exception {this.base = new URL("http://localhost:" + port + "/");}@Testpublic void test() {ResponseEntity<String> test = this.restTemplate.getForEntity(this.base.toString() + "/task", String.class, "test");System.out.println(test.getBody());}
}

7.4@Nested 例:class SpecificationLikeTests {

  @Nested@DisplayName("a calculator")inner class Calculator {val calculator = SampleCalculator()@Testfun `should return the result of adding the first number to the second number`() {val sum = calculator.sum(2, 4)assertEquals(6, sum)}@Testfun `should return the result of subtracting the second number from the first number`() {val subtract = calculator.subtract(4, 2)assertEquals(2, subtract)}}
}

7.5@DisplayName (例见7.4)

7.6@ConfigurationProperties

作用:@ConfigurationProperties的大致作用就是通过它可以把properties或者yml配置直接转成对象。

用法:注解类、方法。

例:1、1yml配置:
spring: redis: dbIndex: 0hostName: 192.168.58.133password: nmamtfport: 6379timeout: 0poolConfig: - maxIdle: 8- minIdle: 0- maxActive: 8- maxWait: -11、2@Component
@ConfigurationProperties(prefix="spring.redis")  
public class RedisProps {private int dbIndex;@NotNullprivate String hostname;private String password;@NotNullprivate int port;private long timeout;private List<Map<String,String>> poolConfig;public int getDbIndex() {return dbIndex;}public void setDbIndex(int dbIndex) {this.dbIndex = dbIndex;}public String getHostname() {return hostname;}public void setHostname(String hostname) {this.hostname = hostname;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public int getPort() {return port;}public void setPort(int port) {this.port = port;}public long getTimeout() {return timeout;}public void setTimeout(long timeout) {this.timeout = timeout;}public List<Map<String, String>> getPoolConfig() {return poolConfig;}public void setPoolConfig(List<Map<String, String>> poolConfig) {this.poolConfig = poolConfig;}}1、3@Configuration  
@EnableAutoConfiguration
public class RedisConfig {@Bean  @ConfigurationProperties(prefix="spring.redis.poolConfig")  public JedisPoolConfig getRedisConfig(){  JedisPoolConfig config = new JedisPoolConfig();return config;  }  @Bean  @ConfigurationProperties(prefix="spring.redis")  public JedisConnectionFactory getConnectionFactory(){  JedisConnectionFactory factory = new JedisConnectionFactory();  factory.setUsePool(true);JedisPoolConfig config = getRedisConfig();  factory.setPoolConfig(config);  return factory;  }  @Bean  public RedisTemplate<?, ?> getRedisTemplate(){  RedisTemplate<?,?> template = new StringRedisTemplate(getConnectionFactory());  return template;  }  
}    
查看全文
如若内容造成侵权/违法违规/事实不符,请联系编程学习网邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

相关文章

  1. Angular的后院:组件依赖关系的解决

    by Dor Moshe通过Dor Moshe Angular的后院&#xff1a;解决 组件依赖关系 (Angular’s Backyard: The Resolving of Components Dependencies) This article originally appeared on dormoshe.io这篇文章 最初出现在dormoshe.io Many of us use the Hierarchical Dependenc…...

    2024/3/26 13:46:50
  2. Spring Boot 学习笔记

    嗯,加油生活,依旧,摘几句子.我十有八九的欲言又止&#xff0c;在日后想来都庆幸。而绝大多数的敞开心扉在事后都追悔。 -------德卡先生的信箱2019.10.3 Spring的发展 Spring1.x 时代&#xff1a;在Spring1.x时代&#xff0c;都是通过xml文件配置bean&#xff0c;随着项目的…...

    2024/3/23 18:57:36
  3. Application of LiDAR in driveless technology

    电子科技大学格拉斯哥学院 2017级 贺俊皓 The car accident happened in Chongqing last month is really a tragedy for all peopel in China.The unreasonalbe female passenger was accused of the crime culprit of this accident. So, which kind of measure could be ada…...

    2024/3/23 20:16:39
  4. paper survey ——Underwater optical communication

    本博文为本人阅读水下通信系列的笔记 Gaussian kernel-aided deep neural network equalizer utilized in underwater PAM8 visible light communication system VLC has advantages that include high speed, the absence of electromagnetic radiation, safety for human ey…...

    2024/3/29 15:56:52
  5. 把这304道React的面试题刷完,前端面试没有在怕的!

    Core React 什么是 React? React 是一个开源前端 JavaScript 库&#xff0c;用于构建用户界面&#xff0c;尤其是单页应用程序。它用于处理网页和移动应用程序的视图层。React 是由 Facebook 的软件工程师 Jordan Walke 创建的。在 2011 年 React 应用首次被部署到 Facebook 的…...

    2024/3/23 20:16:37
  6. 图像质量评价FSIM,matlab代码

    主函数 clc clear all close all; aimread(1.png)); %处理后的图像 A imread(2.jpg)); %源图像 Argb2gray(A);%如果图像是灰度图像&#xff0c;把这句话注释掉 A imresize(A,[256,256]); [FSIM, FSIMc] FeatureSIM(a, A);%这里调用函数&#xff0c; S F…...

    2024/3/23 20:16:34
  7. 前端 基础面试问题汇总

    1>、html5有哪些新标签&#xff1f;<article> 标签定义外部的内容&#xff08;外部内容如blog,news&#xff09;。<aside> 标签定义article以外的内容&#xff08;可用做文章的侧栏&#xff09;。<canvas>使用JavaScript在网页上绘制图形图像。<detail…...

    2024/3/23 20:16:34
  8. griffin编译安装

    Griffin编译安装 前言 Griffin是一个应用于分布式数据系统中的开源数据质量解决方案&#xff0c;例如在Hadoop, Spark, Storm等分布式系统中&#xff0c;Griffin提供了一整套统一的流程来定义和检测数据集的质量并及时报告问题。Apache Griffin是一个开源的大数据数据质量解决…...

    2024/3/23 20:16:32
  9. 小邵教你玩转Generator+co/async await

    前言&#xff1a;大家好&#xff0c;我叫邵威儒&#xff0c;大家都喜欢喊我小邵&#xff0c;学的金融专业却凭借兴趣爱好入了程序猿的坑&#xff0c;从大学买的第一本vb和自学vb&#xff0c;我就与编程结下不解之缘&#xff0c;随后自学易语言写游戏辅助、交易软件&#xff0c;…...

    2024/3/23 20:16:33
  10. 三维空间中的旋转--旋转向量

    处理三维旋转问题时&#xff0c;通常采用旋转矩阵的方式来描述。一个向量乘以旋转矩阵等价于向量以某种方式进行旋转。除了采用旋转矩阵描述外&#xff0c;还可以用旋转向量来描述旋转&#xff0c;旋转向量的长度&#xff08;模&#xff09;表示绕轴逆时针旋转的角度&#xff0…...

    2024/3/26 2:48:57
  11. [转]DCM Tutorial – An Introduction to Orientation Kinematics

    原地址http://www.starlino.com/dcm_tutorial.html Introduction This article is a continuation of my IMU Guide, covering additional orientation kinematics topics. I will go through some theory first and then I will present a practical example with code build …...

    2024/3/23 20:16:28
  12. 华工软院IBM LinuxONE Community Cloud云计算实验文档

    此博文介绍华南理工大学软件学院“云计算开发与应用”实验课。本人在大二期间选修了这门课&#xff0c;实验课内容是把已有的app部署到云服务器上运行。虽然实验内容很简单(作者大概一个小时就做完了两天的实验内容)&#xff0c;但觉得这次实验是我在华工期间做过的为数不多有意…...

    2024/3/23 20:16:27
  13. 7_nodejs angularjs

    webstrom使用&#xff1a; ctrlb/点击&#xff0c;代码导航,自动跳转到定义 ctrln跳转指定类 ctrld复制当前行ctrlenter另起一行ctrly删除当前行 ctrlalt/shiftb跳转方法实现/定义处 包裹/去掉外围代码unwrap... 主题appearance 字体editor-colors&fonts-font 自动换行sett…...

    2024/3/23 20:16:26
  14. 开源cnc项目Marlin2.0运动控制部分代码理解

    本文主要梳理Marlin2.0工程代码中关于运动控制部分的理解。Marlin1.0工程代码用C语言写的&#xff0c;阅读起来比较容易。Marlin1.0主要核心算法包括圆弧插补、速度前瞻、转角速度圆滑、梯形速度规划、Bresenham多轴插补。Marlin2.0工程相对于Marlin1.0工程程序用了更多C的写法…...

    2024/3/23 20:16:25
  15. 命令步骤

    bable 安装: (1):npm install –g babel-cli (2):npm install -g cnpm –registryhttps://registry.npm.taobao.org [国内域] (3):npm install –save-dev babel-preset-es2015(4):type nul>.babelrc [创建] 文 件中写入{“presets”:[‘es2015’]}(5):babel js/es6.js…...

    2024/3/23 20:16:24
  16. 老卫带你学---FSIM特征相似性

    传统全参考图像质量衡量标准FSIM&#xff08;feature similarity&#xff09; ssim一经提出引来了很多人的研究&#xff0c;并在其上进行一系列的变种&#xff0c;其中一种比较成功的变种是FSIM&#xff0c;该算法认为一张图片中的所有像素并非具有相同的重要性&#xff0c;比…...

    2024/3/23 18:57:52
  17. Angularjs 事件指令 input 相关指令 和样式指令 DOM 操作指令详解

    Angularjs 事件指令 input 相关指令 和样式指令DOM 操作指令详解学习要点&#xff1a;1. AngularJs 事件指令2. input 相关指令3. 样式指令4. DOM 操作指令5. ngBind/ngBindHtml/ngBindTemplate 重点6. ng-init ng-mode ng-model-options ng-controler1. Angularjs 事件指令自己…...

    2024/3/23 18:57:50
  18. 前端MVC学习笔记(三)——AngularJS服务、路由、内置API、jQueryLite

    一、服务 AngularJS功能最基本的组件之一是服务(Service)。服务为你的应用提供基于任务的功能。服务可以被视为重复使用的执行一个或多个相关任务的代码块。 AngularJS服务是单例对象&#xff0c;这意味着只有一个实例被创建过&#xff0c;服务使用AngularJS的依赖注入机制来定…...

    2024/3/23 18:57:49
  19. 前端MVC学习总结(三)——AngularJS服务、路由、内置API、jQueryLite

    一、服务 AngularJS功能最基本的组件之一是服务(Service)。服务为你的应用提供基于任务的功能。服务可以被视为重复使用的执行一个或多个相关任务的代码块。 AngularJS服务是单例对象&#xff0c;这意味着只有一个实例被创建过&#xff0c;服务使用AngularJS的依赖注入机制来定…...

    2024/3/23 18:57:48
  20. 前端MVC学习总结(二)——AngularJS验证、过滤器、指令

    一、验证 angularJS中提供了许多的验证指令&#xff0c;可以轻松的实现验证&#xff0c;只需要在表单元素上添加相应的ng属性&#xff0c;常见的如下所示&#xff1a; <input Type"text" ng-model"" [name""] [required""] [ng-req…...

    2024/3/28 23:22:27

最新文章

  1. Facebook多个广告账户被封禁的原因及解决方法

    在昨天的文章中&#xff0c;我们为大家介绍了Facebook是什么&#xff0c;今天我们接着聊一聊如何解决在Facebook投放多个广告时&#xff0c;广告账户被封禁的问题。想必这个问题困扰着包括社交媒体营销人员、内容创作者、跨境电商从业者在内的许多人。不过别担心&#xff0c;有…...

    2024/3/30 0:00:20
  2. 梯度消失和梯度爆炸的一些处理方法

    在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言&#xff0c;在此感激不尽。 权重和梯度的更新公式如下&#xff1a; w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...

    2024/3/20 10:50:27
  3. 前端发版上线出现白屏问题

    目录 路由配置问题资源缓存问题首屏加载过慢 &#xff1a;喂&#xff0c;你的页面白啦&#xff01; 出现上线白屏的问题有很多&#xff0c;如&#xff1a;配置错误、缓存问题、浏览器兼容问题&#xff0c;根据不同情况去解决。 路由配置问题 问题描述&#xff1a; 在vue开发…...

    2024/3/28 17:56:37
  4. GPT4.0

    GPT4.0 支持官网所有功能以及所有第三方GPTS&#xff0c;完全同步官网。无需魔法&#xff0c;填写授权码直达官网。全天超18小时维护&#xff0c;无需担心不稳定。没有永久卡&#xff0c;3.5免费提供&#xff0c;4.0可以按需下单即可&#xff0c;不存在跑路。 需要的联系...

    2024/3/29 13:51:38
  5. 【外汇早评】美通胀数据走低,美元调整

    原标题:【外汇早评】美通胀数据走低,美元调整昨日美国方面公布了新一期的核心PCE物价指数数据,同比增长1.6%,低于前值和预期值的1.7%,距离美联储的通胀目标2%继续走低,通胀压力较低,且此前美国一季度GDP初值中的消费部分下滑明显,因此市场对美联储后续更可能降息的政策…...

    2024/3/29 18:08:39
  6. 【原油贵金属周评】原油多头拥挤,价格调整

    原标题:【原油贵金属周评】原油多头拥挤,价格调整本周国际劳动节,我们喜迎四天假期,但是整个金融市场确实流动性充沛,大事频发,各个商品波动剧烈。美国方面,在本周四凌晨公布5月份的利率决议和新闻发布会,维持联邦基金利率在2.25%-2.50%不变,符合市场预期。同时美联储…...

    2024/3/29 18:08:34
  7. 【外汇周评】靓丽非农不及疲软通胀影响

    原标题:【外汇周评】靓丽非农不及疲软通胀影响在刚结束的周五,美国方面公布了新一期的非农就业数据,大幅好于前值和预期,新增就业重新回到20万以上。具体数据: 美国4月非农就业人口变动 26.3万人,预期 19万人,前值 19.6万人。 美国4月失业率 3.6%,预期 3.8%,前值 3…...

    2024/3/29 2:45:46
  8. 【原油贵金属早评】库存继续增加,油价收跌

    原标题:【原油贵金属早评】库存继续增加,油价收跌周三清晨公布美国当周API原油库存数据,上周原油库存增加281万桶至4.692亿桶,增幅超过预期的74.4万桶。且有消息人士称,沙特阿美据悉将于6月向亚洲炼油厂额外出售更多原油,印度炼油商预计将每日获得至多20万桶的额外原油供…...

    2024/3/29 16:26:39
  9. 【外汇早评】日本央行会议纪要不改日元强势

    原标题:【外汇早评】日本央行会议纪要不改日元强势近两日日元大幅走强与近期市场风险情绪上升,避险资金回流日元有关,也与前一段时间的美日贸易谈判给日本缓冲期,日本方面对汇率问题也避免继续贬值有关。虽然今日早间日本央行公布的利率会议纪要仍然是支持宽松政策,但这符…...

    2024/3/29 5:19:52
  10. 【原油贵金属早评】欧佩克稳定市场,填补伊朗问题的影响

    原标题:【原油贵金属早评】欧佩克稳定市场,填补伊朗问题的影响近日伊朗局势升温,导致市场担忧影响原油供给,油价试图反弹。此时OPEC表态稳定市场。据消息人士透露,沙特6月石油出口料将低于700万桶/日,沙特已经收到石油消费国提出的6月份扩大出口的“适度要求”,沙特将满…...

    2024/3/29 18:08:00
  11. 【外汇早评】美欲与伊朗重谈协议

    原标题:【外汇早评】美欲与伊朗重谈协议美国对伊朗的制裁遭到伊朗的抗议,昨日伊朗方面提出将部分退出伊核协议。而此行为又遭到欧洲方面对伊朗的谴责和警告,伊朗外长昨日回应称,欧洲国家履行它们的义务,伊核协议就能保证存续。据传闻伊朗的导弹已经对准了以色列和美国的航…...

    2024/3/29 11:11:56
  12. 【原油贵金属早评】波动率飙升,市场情绪动荡

    原标题:【原油贵金属早评】波动率飙升,市场情绪动荡因中美贸易谈判不安情绪影响,金融市场各资产品种出现明显的波动。随着美国与中方开启第十一轮谈判之际,美国按照既定计划向中国2000亿商品征收25%的关税,市场情绪有所平复,已经开始接受这一事实。虽然波动率-恐慌指数VI…...

    2024/3/29 1:13:26
  13. 【原油贵金属周评】伊朗局势升温,黄金多头跃跃欲试

    原标题:【原油贵金属周评】伊朗局势升温,黄金多头跃跃欲试美国和伊朗的局势继续升温,市场风险情绪上升,避险黄金有向上突破阻力的迹象。原油方面稍显平稳,近期美国和OPEC加大供给及市场需求回落的影响,伊朗局势并未推升油价走强。近期中美贸易谈判摩擦再度升级,美国对中…...

    2024/3/29 8:28:16
  14. 【原油贵金属早评】市场情绪继续恶化,黄金上破

    原标题:【原油贵金属早评】市场情绪继续恶化,黄金上破周初中国针对于美国加征关税的进行的反制措施引发市场情绪的大幅波动,人民币汇率出现大幅的贬值动能,金融市场受到非常明显的冲击。尤其是波动率起来之后,对于股市的表现尤其不安。隔夜美国股市出现明显的下行走势,这…...

    2024/3/29 7:41:19
  15. 【外汇早评】美伊僵持,风险情绪继续升温

    原标题:【外汇早评】美伊僵持,风险情绪继续升温昨日沙特两艘油轮再次发生爆炸事件,导致波斯湾局势进一步恶化,市场担忧美伊可能会出现摩擦生火,避险品种获得支撑,黄金和日元大幅走强。美指受中美贸易问题影响而在低位震荡。继5月12日,四艘商船在阿联酋领海附近的阿曼湾、…...

    2024/3/29 18:07:15
  16. 【原油贵金属早评】贸易冲突导致需求低迷,油价弱势

    原标题:【原油贵金属早评】贸易冲突导致需求低迷,油价弱势近日虽然伊朗局势升温,中东地区几起油船被袭击事件影响,但油价并未走高,而是出于调整结构中。由于市场预期局势失控的可能性较低,而中美贸易问题导致的全球经济衰退风险更大,需求会持续低迷,因此油价调整压力较…...

    2024/3/29 9:57:23
  17. 氧生福地 玩美北湖(上)——为时光守候两千年

    原标题:氧生福地 玩美北湖(上)——为时光守候两千年一次说走就走的旅行,只有一张高铁票的距离~ 所以,湖南郴州,我来了~ 从广州南站出发,一个半小时就到达郴州西站了。在动车上,同时改票的南风兄和我居然被分到了一个车厢,所以一路非常愉快地聊了过来。 挺好,最起…...

    2024/3/29 0:49:46
  18. 氧生福地 玩美北湖(中)——永春梯田里的美与鲜

    原标题:氧生福地 玩美北湖(中)——永春梯田里的美与鲜一觉醒来,因为大家太爱“美”照,在柳毅山庄去寻找龙女而错过了早餐时间。近十点,向导坏坏还是带着饥肠辘辘的我们去吃郴州最富有盛名的“鱼头粉”。说这是“十二分推荐”,到郴州必吃的美食之一。 哇塞!那个味美香甜…...

    2024/3/29 18:06:57
  19. 氧生福地 玩美北湖(下)——奔跑吧骚年!

    原标题:氧生福地 玩美北湖(下)——奔跑吧骚年!让我们红尘做伴 活得潇潇洒洒 策马奔腾共享人世繁华 对酒当歌唱出心中喜悦 轰轰烈烈把握青春年华 让我们红尘做伴 活得潇潇洒洒 策马奔腾共享人世繁华 对酒当歌唱出心中喜悦 轰轰烈烈把握青春年华 啊……啊……啊 两…...

    2024/3/29 17:27:19
  20. 扒开伪装医用面膜,翻六倍价格宰客,小姐姐注意了!

    原标题:扒开伪装医用面膜,翻六倍价格宰客,小姐姐注意了!扒开伪装医用面膜,翻六倍价格宰客!当行业里的某一品项火爆了,就会有很多商家蹭热度,装逼忽悠,最近火爆朋友圈的医用面膜,被沾上了污点,到底怎么回事呢? “比普通面膜安全、效果好!痘痘、痘印、敏感肌都能用…...

    2024/3/29 18:06:36
  21. 「发现」铁皮石斛仙草之神奇功效用于医用面膜

    原标题:「发现」铁皮石斛仙草之神奇功效用于医用面膜丽彦妆铁皮石斛医用面膜|石斛多糖无菌修护补水贴19大优势: 1、铁皮石斛:自唐宋以来,一直被列为皇室贡品,铁皮石斛生于海拔1600米的悬崖峭壁之上,繁殖力差,产量极低,所以古代仅供皇室、贵族享用 2、铁皮石斛自古民间…...

    2024/3/29 18:06:22
  22. 丽彦妆\医用面膜\冷敷贴轻奢医学护肤引导者

    原标题:丽彦妆\医用面膜\冷敷贴轻奢医学护肤引导者【公司简介】 广州华彬企业隶属香港华彬集团有限公司,专注美业21年,其旗下品牌: 「圣茵美」私密荷尔蒙抗衰,产后修复 「圣仪轩」私密荷尔蒙抗衰,产后修复 「花茵莳」私密荷尔蒙抗衰,产后修复 「丽彦妆」专注医学护…...

    2024/3/28 18:26:34
  23. 广州械字号面膜生产厂家OEM/ODM4项须知!

    原标题:广州械字号面膜生产厂家OEM/ODM4项须知!广州械字号面膜生产厂家OEM/ODM流程及注意事项解读: 械字号医用面膜,其实在我国并没有严格的定义,通常我们说的医美面膜指的应该是一种「医用敷料」,也就是说,医用面膜其实算作「医疗器械」的一种,又称「医用冷敷贴」。 …...

    2024/3/29 18:06:01
  24. 械字号医用眼膜缓解用眼过度到底有无作用?

    原标题:械字号医用眼膜缓解用眼过度到底有无作用?医用眼膜/械字号眼膜/医用冷敷眼贴 凝胶层为亲水高分子材料,含70%以上的水分。体表皮肤温度传导到本产品的凝胶层,热量被凝胶内水分子吸收,通过水分的蒸发带走大量的热量,可迅速地降低体表皮肤局部温度,减轻局部皮肤的灼…...

    2024/3/28 20:09:10
  25. 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...

    解析如下&#xff1a;1、长按电脑电源键直至关机&#xff0c;然后再按一次电源健重启电脑&#xff0c;按F8健进入安全模式2、安全模式下进入Windows系统桌面后&#xff0c;按住“winR”打开运行窗口&#xff0c;输入“services.msc”打开服务设置3、在服务界面&#xff0c;选中…...

    2022/11/19 21:17:18
  26. 错误使用 reshape要执行 RESHAPE,请勿更改元素数目。

    %读入6幅图像&#xff08;每一幅图像的大小是564*564&#xff09; f1 imread(WashingtonDC_Band1_564.tif); subplot(3,2,1),imshow(f1); f2 imread(WashingtonDC_Band2_564.tif); subplot(3,2,2),imshow(f2); f3 imread(WashingtonDC_Band3_564.tif); subplot(3,2,3),imsho…...

    2022/11/19 21:17:16
  27. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机...

    win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”问题的解决方法在win7系统关机时如果有升级系统的或者其他需要会直接进入一个 等待界面&#xff0c;在等待界面中我们需要等待操作结束才能关机&#xff0c;虽然这比较麻烦&#xff0c;但是对系统进行配置和升级…...

    2022/11/19 21:17:15
  28. 台式电脑显示配置100%请勿关闭计算机,“准备配置windows 请勿关闭计算机”的解决方法...

    有不少用户在重装Win7系统或更新系统后会遇到“准备配置windows&#xff0c;请勿关闭计算机”的提示&#xff0c;要过很久才能进入系统&#xff0c;有的用户甚至几个小时也无法进入&#xff0c;下面就教大家这个问题的解决方法。第一种方法&#xff1a;我们首先在左下角的“开始…...

    2022/11/19 21:17:14
  29. win7 正在配置 请勿关闭计算机,怎么办Win7开机显示正在配置Windows Update请勿关机...

    置信有很多用户都跟小编一样遇到过这样的问题&#xff0c;电脑时发现开机屏幕显现“正在配置Windows Update&#xff0c;请勿关机”(如下图所示)&#xff0c;而且还需求等大约5分钟才干进入系统。这是怎样回事呢&#xff1f;一切都是正常操作的&#xff0c;为什么开时机呈现“正…...

    2022/11/19 21:17:13
  30. 准备配置windows 请勿关闭计算机 蓝屏,Win7开机总是出现提示“配置Windows请勿关机”...

    Win7系统开机启动时总是出现“配置Windows请勿关机”的提示&#xff0c;没过几秒后电脑自动重启&#xff0c;每次开机都这样无法进入系统&#xff0c;此时碰到这种现象的用户就可以使用以下5种方法解决问题。方法一&#xff1a;开机按下F8&#xff0c;在出现的Windows高级启动选…...

    2022/11/19 21:17:12
  31. 准备windows请勿关闭计算机要多久,windows10系统提示正在准备windows请勿关闭计算机怎么办...

    有不少windows10系统用户反映说碰到这样一个情况&#xff0c;就是电脑提示正在准备windows请勿关闭计算机&#xff0c;碰到这样的问题该怎么解决呢&#xff0c;现在小编就给大家分享一下windows10系统提示正在准备windows请勿关闭计算机的具体第一种方法&#xff1a;1、2、依次…...

    2022/11/19 21:17:11
  32. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”的解决方法...

    今天和大家分享一下win7系统重装了Win7旗舰版系统后&#xff0c;每次关机的时候桌面上都会显示一个“配置Windows Update的界面&#xff0c;提示请勿关闭计算机”&#xff0c;每次停留好几分钟才能正常关机&#xff0c;导致什么情况引起的呢&#xff1f;出现配置Windows Update…...

    2022/11/19 21:17:10
  33. 电脑桌面一直是清理请关闭计算机,windows7一直卡在清理 请勿关闭计算机-win7清理请勿关机,win7配置更新35%不动...

    只能是等着&#xff0c;别无他法。说是卡着如果你看硬盘灯应该在读写。如果从 Win 10 无法正常回滚&#xff0c;只能是考虑备份数据后重装系统了。解决来方案一&#xff1a;管理员运行cmd&#xff1a;net stop WuAuServcd %windir%ren SoftwareDistribution SDoldnet start WuA…...

    2022/11/19 21:17:09
  34. 计算机配置更新不起,电脑提示“配置Windows Update请勿关闭计算机”怎么办?

    原标题&#xff1a;电脑提示“配置Windows Update请勿关闭计算机”怎么办&#xff1f;win7系统中在开机与关闭的时候总是显示“配置windows update请勿关闭计算机”相信有不少朋友都曾遇到过一次两次还能忍但经常遇到就叫人感到心烦了遇到这种问题怎么办呢&#xff1f;一般的方…...

    2022/11/19 21:17:08
  35. 计算机正在配置无法关机,关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机...

    关机提示 windows7 正在配置windows 请勿关闭计算机 &#xff0c;然后等了一晚上也没有关掉。现在电脑无法正常关机以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;关机提示 windows7 正在配…...

    2022/11/19 21:17:05
  36. 钉钉提示请勿通过开发者调试模式_钉钉请勿通过开发者调试模式是真的吗好不好用...

    钉钉请勿通过开发者调试模式是真的吗好不好用 更新时间:2020-04-20 22:24:19 浏览次数:729次 区域: 南阳 > 卧龙 列举网提醒您:为保障您的权益,请不要提前支付任何费用! 虚拟位置外设器!!轨迹模拟&虚拟位置外设神器 专业用于:钉钉,外勤365,红圈通,企业微信和…...

    2022/11/19 21:17:05
  37. 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...

    前几天班里有位学生电脑(windows 7系统)出问题了&#xff0c;具体表现是开机时一直停留在“配置windows update失败 还原更改 请勿关闭计算机”这个界面&#xff0c;长时间没反应&#xff0c;无法进入系统。这个问题原来帮其他同学也解决过&#xff0c;网上搜了不少资料&#x…...

    2022/11/19 21:17:04
  38. 一个电脑无法关闭计算机你应该怎么办,电脑显示“清理请勿关闭计算机”怎么办?...

    本文为你提供了3个有效解决电脑显示“清理请勿关闭计算机”问题的方法&#xff0c;并在最后教给你1种保护系统安全的好方法&#xff0c;一起来看看&#xff01;电脑出现“清理请勿关闭计算机”在Windows 7(SP1)和Windows Server 2008 R2 SP1中&#xff0c;添加了1个新功能在“磁…...

    2022/11/19 21:17:03
  39. 请勿关闭计算机还原更改要多久,电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机怎么办...

    许多用户在长期不使用电脑的时候&#xff0c;开启电脑发现电脑显示&#xff1a;配置windows更新失败&#xff0c;正在还原更改&#xff0c;请勿关闭计算机。。.这要怎么办呢&#xff1f;下面小编就带着大家一起看看吧&#xff01;如果能够正常进入系统&#xff0c;建议您暂时移…...

    2022/11/19 21:17:02
  40. 还原更改请勿关闭计算机 要多久,配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以...

    配置windows update失败 还原更改 请勿关闭计算机&#xff0c;电脑开机后一直显示以以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;配置windows update失败 还原更改 请勿关闭计算机&#x…...

    2022/11/19 21:17:01
  41. 电脑配置中请勿关闭计算机怎么办,准备配置windows请勿关闭计算机一直显示怎么办【图解】...

    不知道大家有没有遇到过这样的一个问题&#xff0c;就是我们的win7系统在关机的时候&#xff0c;总是喜欢显示“准备配置windows&#xff0c;请勿关机”这样的一个页面&#xff0c;没有什么大碍&#xff0c;但是如果一直等着的话就要两个小时甚至更久都关不了机&#xff0c;非常…...

    2022/11/19 21:17:00
  42. 正在准备配置请勿关闭计算机,正在准备配置windows请勿关闭计算机时间长了解决教程...

    当电脑出现正在准备配置windows请勿关闭计算机时&#xff0c;一般是您正对windows进行升级&#xff0c;但是这个要是长时间没有反应&#xff0c;我们不能再傻等下去了。可能是电脑出了别的问题了&#xff0c;来看看教程的说法。正在准备配置windows请勿关闭计算机时间长了方法一…...

    2022/11/19 21:16:59
  43. 配置失败还原请勿关闭计算机,配置Windows Update失败,还原更改请勿关闭计算机...

    我们使用电脑的过程中有时会遇到这种情况&#xff0c;当我们打开电脑之后&#xff0c;发现一直停留在一个界面&#xff1a;“配置Windows Update失败&#xff0c;还原更改请勿关闭计算机”&#xff0c;等了许久还是无法进入系统。如果我们遇到此类问题应该如何解决呢&#xff0…...

    2022/11/19 21:16:58
  44. 如何在iPhone上关闭“请勿打扰”

    Apple’s “Do Not Disturb While Driving” is a potentially lifesaving iPhone feature, but it doesn’t always turn on automatically at the appropriate time. For example, you might be a passenger in a moving car, but your iPhone may think you’re the one dri…...

    2022/11/19 21:16:57