spring annotations

Annotations for declaring Beans:
@Component : Components, no clear roles
@Service : Use @Repository in the business logic layer (service layer): Use
in the data access layer (dao layer).
@Controller : In the presentation layer (MVC--SpringMVC ) Use annotations for

injecting beans:
@Aautowired : Annotations provided by Spring.
@Inject : Annotations provided by JSR-330
@Resource : Annotations provided by JSR-250

Configuration file annotations:
@Configuration : Declare that the current class is a configuration class, equivalent to A Spring configuration xml file.
@ComponentScan (cn.test.demo): Automatically scan all classes under the package name that use @Component @Service @Repository @Controller and register as Bean
@WiselyConfiguration : Combined annotations can replace @Configuration and @ ComponentScan
@Bean : Annotated on the method, declaring that the return value of the current method is a Bean.
@Bean(initMethod="aa", destroyMethod="bb")--> Specifies that the aa and bb methods are executed after construction and before the Bean is destroyed .

AOP aspect programming annotation:
@Aspect : declares that this is an aspect
@After @Before. @Around defines the aspect, you can directly use the interception rule (pointcut PointCut) as a parameter
@PointCut : Specially define the interception rule and then call @Transcational in @After @Before. @Around
: Transaction processing
@Cacheable : Data cache
@EnableAaspectJAutoProxy: Enable Spring's support for this aspect (Aspect)
@Target (ElementType.TYPE): Meta-annotation, used to specify the member of the annotation-modified class --> Specify the interception rule
@Retention(RetentionPolicy.RUNTIME)
---> When the @Retention of the defined annotation is RUNTIME, the annotation can be processed through the runtime reflection mechanism.-->Specify the interception rule

Spring common configuration:
@import : import configuration class
@Scope : create an instance of a new bean @Scope(" prototype") declares Scope as Prototype
@Value : property injection
@Value ("I love you") --> normal string injection
@Value ("#{systemProperties['os.name']}") --> injection operation System property
@Value ("#{ T (java.lang.Math).random() * 100.0 }") --> inject expression result
@Value ("#{demoService.another}") --> inject other bean properties
@Value ( "classpath:com/wisely/highlight_spring4/ch2/el/test.txt" ) --> inject file resources
@Value (" http://www.baidu.com")-->Inject URL resource
@Value ("${book.name}" ) -->Inject configuration file Note: Use $ instead of #
@PostConstruct : in the constructor Execute @PreDestroy after execution : execute @ActiveProfiles
before the bean is destroyed : declare the active profile @profile: provide support for using different configurations in different environments @Profile("dev")  …. The method named dev-xxxx provides instantiated beans @EnableAsync : Enables support for asynchronous tasks (multi-threading) @Asyncs : Declare that this is an asynchronous task, which can be declared at the class level and method level. @EnableScheduling : Enable scheduled tasks Support for (timer) @Scheduled : Declare that this is a scheduled task to support multiple scheduled tasks, including cron. fixDelay fixRate @Scheduled (dixedDelay = 5000) Regular update via annotation @Conditional : Conditional annotation, Create a specific bean based on meeting a specific condition









@ContextConfiguration : Load the configuration file
@ContextConfiguration(classes = {TestConfig.class})
@ContextConfiguration is used to load the ApplicationContext
classes property is used to load the configuration class
@WebAppCofiguration : Specifies that the loaded ApplicationContext is a WebApplicationContext
@Enable* annotation:
@EnableAsync : Enables asynchronous tasks Support (multi-threading)
@EnableScheduling : Enable support for scheduled tasks (timers)
@EnableWebMVC : Enable configuration support for Web MVC
@EnableAaspectJAutoProxy : Enable Spring's support for this aspect (Aspect )
@EnableConfigurationProperties Enable annotation configuration for @ConfigurationProperties Bean support
@EnableJpaRepositories : Enable support for Spring Data JAP Repository
@EnableTransactionManagement Enable support for
annotations

@EnableEurekaServer registers the server spring cloud to implement service registration @
@EnableScheduling allows spring to schedule tasks, the function is similar to the namespace in the spring.xml file <task:*>
@EnableCaching enables Cache caching support;
SpringMVC common annotations:
@Controller : annotation Declare this class on the class as a Controller in springmvc, and declare it as a spring bean.
@RequestMapping : You can annotate the class and method to map WEB requests (access paths and parameters)
@RequestMapping(value= "/convert" ,produces+{"application/x-wisely"}) set the access URL return value type
@ResponseBody : support putting the return value into the response body instead of returning a page (returning a group of data)
@RequestBody : allowing request parameters in In the request body, instead of being directly connected after the address, the secondary annotation is placed before the parameter
@Path Variable : used to receive path parameters such as /test/001,001 as a parameter, and the secondary annotation is placed before the parameter
@RestController : @Controller + @ResponseBody combined annotation
@ControllerAdvice : Through @ControllerAdvice, the global configuration of the controller can be placed in the same location
@ExceptionHandler : Used to handle the exception of the controller globally
@ExceptionHandier(value=Exception.class) --> The interceptor conditions can be filtered through the value attribute, and all exceptions can be intercepted
@InitBinder: used to set WebDataBinder, WebDataBinder is used to automatically bind foreground request parameters to Model.
@ModelAttrbuute: bind Set the key-value pair to the Model,
@RunWith : The runner
@RunWith(JUnit4.class) refers to using JUnit4 to run
@RunWith(SpringJUnit4ClassRunner.class), and letting the test run in the Spring test environment
@RunWith(Suite.class) is A set of test collections,
@WebAppConfiguration("src/main/resources") : Annotated on the class, used to declare that the loaded ApplicationContext is a WebApplicationContext, and its properties specify the location of Web resources, the default is src/main/webapp , custom modified to resource @Before : Initialize Spring Boot annotation
before xxx : @SpringBootApplication : It is the core annotation of the Spring Boot project. The main purpose is to enable automatic configuration. The @SpringBootApplication annotation is a combination annotation, which mainly combines @Configuration .+@EnableAutoConfiguration .+@ComponentScan




@Value : Property injection, read properties in properties or Yml file
@ConfigurationProperties : Associate the properties property with a Bean and its properties to achieve type-safe configuration
@ConfigurationProperties(prefix = "author", locations = {"classpath: config/author.properties"})
Load the configuration through @ConfigurationProperties, specify the configuration prefix through the prefix attribute, and specify the configuration file location through the location
@EnableAutoConfiguration Annotation: The function is to let Spring Boot automatically configure
        the Spring framework according to the dependencies declared by the application. The annotation tells Spring Boot to guess how you want to configure Spring based on the added jar dependencies. Since spring-boot-starter-web adds Tomcat and Spring MVC, auto-configuration will assume you are developing a web application and set up Spring accordingly.
@Configuration annotation to clearly indicate that this class is the source of information for bean configuration The
@ComponentScan annotation tells Spring to scan the specified package to initialize Spring Beans. This ensures that the beans we declare can be discovered.
The @ImportResource annotation loads the XML configuration file
@EnableAutoConfiguration(exclude={xxxx.class}) to disable specific auto-configuration
The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration and @ComponentScan with default properties.


@SuppressWarnings Annotation
@SuppressWarnings("unchecked")
tells the compiler to ignore unchecked warnings, such as warnings generated by unparameterized use of list ArrayList
@SuppressWarnings("serial")
If the compiler displays such warnings: The serializable class WmailCalendar does not declare a static final serialVersionUID field of type long Use this comment to get rid of the warning.
@SuppressWarnings("deprecation")
The compiler will warn you if a method annotated with @Deprecated is used. Use this comment to get rid of the warning message.
@SuppressWarnings("unchecked", "deprecation")
tells the compiler to ignore both unchecked and deprecation warnings.
@SuppressWarnings(value={"unchecked", "deprecation"}) is
equivalent to @SuppressWarnings("unchecked", "



@Table(name ="S_PRODUCEINFO")
@Data
@NoArgsConstructor
@AllArgsConstructor
publicclassProduceInfoEntity {

    @Id
    @Column(name = "app_name", unique =true, length = 50)
    privateStringname;

    @Column(name = "status")
    @Enumerated(EnumType.STRING)
    privateProduceStatusstatus;

    @Column(name = "create_time", updatable =false)
    @Temporal(TemporalType.TIMESTAMP)
    @CreationTimestamp
    privateDatecreateTime;

    @Column(name = "update_time")
    @Temporal(TemporalType.TIMESTAMP)
    @UpdateTimestamp
    privateDateupdateTime;

@Entity :Mapping database entity classes
@Table(name = "S_PRODUCEINFO") : The table name is "S_PRODUCEINFO"
@Id : Declare the primary key ID
@Column(name = "app_name", unique =true, length = 50) : Corresponding database field, attribute
@Enumerated(EnumType. STRING) : Use enumeration value type to interact with database fields
@Temporal : Time format mapping database will get date in specified time format
       @Enumerted(EnumType.STRING) HH:MM:SS format date
      @Enumerted(EnumType.DATE) Get Year month day yyyy-MM-dd
       @Enumerted(EnumType.TIME) to get the hour, minute and second HH:MM:SS

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326817433&siteId=291194637