To turn on the automatic scanning feature before using annotations
Where Base-package is the package (with child packages) that needs to be scanned.
| 1 |
<context:component-scan base-package="cn.test"/> |
@Configuration use a class as an IOC container, and one of its method headers, if registered with @bean, is used as the Bean in the spring container.
@Scope Annotation Scopes
@Lazy (True) indicates deferred initialization
@Service for labeling business layer components,
@Controller for labeling control-layer components, such as action in struts
@Repository is used to label data access Components, or DAO components.
@Component refer to components, we can use this annotation when the component is poorly categorized.
@Scope used to specify scope scope (used on a class)
---------------jsr250----
@PostConstruct used to specify the initialization method (used on the method)
@PreDestory used to specify the method of destruction (used on methods)
@Resource is assembled by name by default, and the bean that matches the name is not found to be assembled by type.
----------
@DependsOn: Defines the order in which beans are initialized and destroyed
@Primary: When multiple bean candidates appear in automatic assembly, the Bean Annotated as @primary will be the preferred one, or an exception will be thrown
The @Autowired is assembled by type by default, and can be used in conjunction with @qualifier annotations if we want to use the assemble by name. As follows:
@Autowired @Qualifier ("Persondaobean") exist with multiple instances
@PostConstruct initialization annotations
@PreDestroy destroy annotations The default single-instance startup is loaded??
@Async an asynchronous method call, you need to add the following code:
| 12345 |
<bean id= "Taskexecutor" class = " Org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor " > Code class= "Java plain" ><property name= "corepoolsize" value= /> <property name= "maxpoolsize" value= "" /> </BEAN> <TASK:ANNOTATION-DRIVEN/> |
In order for @async annotations to take effect, you also need to configure @enableasync in the main program of spring boot
In spring, a method based on @async notation is called an asynchronous method;
These methods will be executed in a separate thread at the time of execution,
The caller does not have to wait for it to complete,
You can continue with other operations.
The function that the @Async modifies is not defined as a static type, so that the asynchronous call does not take effect
@ComponentScan (basepackages = "com.xzc.")
@EnableAutoConfiguration
@SpringBootApplication
@PropertySource ({"Classpath:application.properties", "Classpath:xzc.properties"})
@ImportResource ("Classpath:ws-client.xml")
@EnableRedisHttpSession
@EnableAspectJAutoProxy
@EnableCaching
@EnableAsync
@Configuration
@EnableScheduling Start a scheduled task
Springcloud (3-2) Summary of various spring annotations