FANDOM


Overview

Spring Framework

References

General

Notes

  • Annotation injection is performed before XML injection, thus the latter configuration will override the former for properties wired through both approaches.
  • The @Required annotation simply indicates that the affected bean property must be populated at configuration time, through an explicit property value in a bean definition or through autowiring. The container throws an exception if the affected bean property has not been populated; this allows for eager and explicit failure, avoiding NullPointerExceptions or the like later on. It is still recommended that you put assertions into the bean class itself, for example, into an init method. Doing so enforces those required references and values even when you use the class outside of a container.

Resource

Container

Benas

  <bean id="registeringIdentificationListener" class="org.springframework.beans.factory.config.MethodInvokingBean"
    depends-on="listenableDetectionService, defaultDetectionListener">
    <property name="targetObject" ref="listenableDetectionService"/>
    <property name="targetMethod" value="addListener"/>
    <property name="arguments" ref="defaultDetectionListener"/>
  </bean>

Configuration

Annotations

  • Packages
Purpose Package Annotations
Denoting the roles of types or methods in the overall architecture org.springframework.stereotype @Component, @Controller, @Repository, @Service
Bean configuration org.springframework.beans.factory.annotation @Autowired, @Required, @Value, ...
ApplicationContext support org.springframework.context.annotation @Bean, @ComponentScan, @Conditional, @Configuration, @Lazy, @Profile, @Scope, ...
Asynchronous method execution org.springframework.scheduling.annotation @Async, @Scheduled
Binding requests to controllers and handler methods org.springframework.web.bind.annotation @RestController, @GetMapping, @PostMapping, @PutMapping, @PathVariable, @RequestBody, @ResponseBody, ...
Transaction demarcation org.springframework.transaction.annotation @Transactional, @EnableTransactionManagement
Annotation-driven tests org.springframework.test.annotation @IfProfileValue, @Repeat, @Rollback, @Timed
MBean exposure org.springframework.jmx.export.annotation
Declaratively configuring field formatting rules org.springframework.format.annotation @DateTimeFormat, @NumberFormat
Spring Boot's auto-configuration capabilities. org.springframework.boot.autoconfigure EnableAutoConfiguration, SpringBootApplication

SpEL

Transaction

AOP

Concurrency

  • API
    • TaskExecutor
      • Simple task executor interface that abstracts the execution of a Runnable.
    • ConcurrentTaskExecutor
      • Adapter that takes a java.util.concurrent.Executor and exposes a Spring TaskExecutor for it.
    • ExecutorServiceAdapter
      • Adapter that takes a Spring TaskExecutor and exposes a full java.util.concurrent.ExecutorService for it.
    • ThreadPoolTaskExecutor
      • JavaBean that allows for configuring a ThreadPoolExecutor in bean style (through its "corePoolSize", "maxPoolSize", "keepAliveSeconds", "queueCapacity" properties) and exposing it as a Spring TaskExecutor.
    • ThreadPoolExecutorFactoryBean
      • JavaBean that allows for configuring a ThreadPoolExecutor in bean style (through its "corePoolSize", "maxPoolSize", "keepAliveSeconds", "queueCapacity" properties) and exposing it as a bean reference of its native ExecutorService type.
    • @Scheduled
    • @Async

Internationalization

MVC

REST

JMX

  • ManagedResource Annotation is not annoted as Inherited
    • We finally changed @ManagedResource to inherited now. Potential object name collisions need to be dealt with; the general recommendation is to not specify an object name value in @ManagedResource at all when using it on a base class.

Jackson

misc

Spring Boot

References

General

Config

Actuator

Error

REST

Test

Spring Security

References

Concepts

Concept Description API Remarks
Principal the abstract notion of a principal, which can be used to represent any entity, such as an individual, a corporation, and a login id java.security.Principal Party
Subject a grouping of related information for a single entity, such as a person, including the Subject's identities as well as its security-related attributes (passwords and cryptographic keys, for example) javax.security.auth.Subject A subject can contain multiple principals and a principal represents the face of a subject.
Authentication authenticated principal org.springframework.security.core.Authentication interface Authentication extends Principal
GrantedAuthority application-wide permissions granted to a principal org.springframework.security.core.GrantedAuthority Role

Core Component

Component API Source Remarks
Authentication org.springframework.security.core.Authentication
UsernamePasswordAuthenticationToken org.springframework.security.authentication.UsernamePasswordAuthenticationToken An Authentication implementation that is designed for simple presentation of a username and password
TestingAuthenticationToken org.springframework.security.authentication.TestingAuthenticationToken An Authentication implementation that is designed for use whilst unit testing

General

Session Management

Authentication

Authorization

Spring Session

References

Spring Cloud

misc

XML Schemas

Samples

Working of @Transactional annotation according to the processing mode(proxy or aspectj)

Test code outline
  • Annotated method is private : private SearchRequest createAndPersistNewSearchReq()
  • In-call is invoked from testProcess to createAndPersistNewSearchReq()
  1. public class SearchTaskProcessorTest{
  2.  
  3.   //...
  4.   ConfigurableApplicationContext spring;
  5.   private SearchMasterMapper masterMapper;
  6.   private SearchDetailMapper detailMapper;
  7.   private SearchRoiMapper roiMapper;
  8.   private SearchRoiParamMapper roiParamMapper;
  9.   private SearchRoiPointMapper roiPointMapper;
  10.  
  11.   @BeforeClass
  12.   public void beforeClass() throws Exception{
  13.  
  14.     //...
  15.     this.spring = new ClassPathXmlApplicationContext(CONFIG_LOCATION);
  16.     this.spring.registerShutdownHook();
  17.     this.masterMapper = this.spring.getBean("searchMasterMapper", SearchMasterMapper.class);
  18.     this.detailMapper = this.spring.getBean("searchDetailMapper", SearchDetailMapper.class);
  19.     this.roiMapper = this.spring.getBean("searchRoiMapper", SearchRoiMapper.class);
  20.     this.roiParamMapper = this.spring.getBean("searchRoiParamMapper", SearchRoiParamMapper.class);
  21.     this.roiPointMapper = this.spring.getBean("searchRoiPointMapper", SearchRoiPointMapper.class);
  22.   }
  23.  
  24.   @AfterClass
  25.   public void afterClass(){ }
  26.  
  27.   @Transactional
  28.   private SearchRequest createAndPersistNewSearchReq(){
  29.  
  30.     //...
  31.     this.masterMapper.insertSearchMaster(req);
  32.     this.detailMapper.insertSearchDetail(req.getId(), cctv);
  33.     this.roiMapper.insertSearchRoi(req.getId(), cctv.getSystemId(), cctv.getId(), roi);
  34.  
  35.     for(Param param: roi.getParams()){
  36.       this.roiParamMapper.insertSearchRoiParam(req.getId(), cctv.getSystemId(),
  37.         cctv.getId(), roi.getNo(), param);
  38.     }
  39.     for(Point pt: roi.getPoints()){
  40.       this.roiPointMapper.insertSearchRoiPoint(req.getId(), cctv.getSystemId(),
  41.         cctv.getId(), roi.getNo(), pt);
  42.     }
  43.  
  44.     return req;
  45.   }
  46.  
  47.   @Test
  48.   public void testProcess(){
  49.  
  50.     SearchRequest req = this.createAndPersistNewSearchReq();
  51.     SearchTaskProcessor processor = this.spring.getBean(...);
  52.  
  53.     //...
  54.  
  55.     processor.process(req.getId(), "1", crtr);
  56.   }
  57. }


In proxy mode
  • Log
  1.