3rdstage's Wiki
Advertisement

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 @ManagedResource, ManagedAttribute, ManagedOperation
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 Control

REST

Test

Class/Package Description Remarks
Annotation Type SpringBootTest Annotation that can be specified on a test class that runs Spring Boot based tests
Enum SpringBootTest.WebEnvironment An enumeration web environment modes DEFINED_PORT, MOCK, NONE, RANDOM_PORT
Annotation Type MockBean Annotation that can be used to add mocks to a Spring ApplicationContext
Class SpringExtension integrates the Spring TestContext Framework into JUnit 5's Jupiter programming model.

misc

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()
public class SearchTaskProcessorTest{

  //...
  ConfigurableApplicationContext spring;
  private SearchMasterMapper masterMapper;
  private SearchDetailMapper detailMapper;
  private SearchRoiMapper roiMapper;
  private SearchRoiParamMapper roiParamMapper;
  private SearchRoiPointMapper roiPointMapper;

  @BeforeClass
  public void beforeClass() throws Exception{

    //...
    this.spring = new ClassPathXmlApplicationContext(CONFIG_LOCATION);
    this.spring.registerShutdownHook();
    this.masterMapper = this.spring.getBean("searchMasterMapper", SearchMasterMapper.class);
    this.detailMapper = this.spring.getBean("searchDetailMapper", SearchDetailMapper.class);
    this.roiMapper = this.spring.getBean("searchRoiMapper", SearchRoiMapper.class);
    this.roiParamMapper = this.spring.getBean("searchRoiParamMapper", SearchRoiParamMapper.class);
    this.roiPointMapper = this.spring.getBean("searchRoiPointMapper", SearchRoiPointMapper.class);
  }

  @AfterClass
  public void afterClass(){ }

  @Transactional
  private SearchRequest createAndPersistNewSearchReq(){

    //...
    this.masterMapper.insertSearchMaster(req);
    this.detailMapper.insertSearchDetail(req.getId(), cctv);
    this.roiMapper.insertSearchRoi(req.getId(), cctv.getSystemId(), cctv.getId(), roi);

    for(Param param: roi.getParams()){
      this.roiParamMapper.insertSearchRoiParam(req.getId(), cctv.getSystemId(),
        cctv.getId(), roi.getNo(), param);
    }
    for(Point pt: roi.getPoints()){
      this.roiPointMapper.insertSearchRoiPoint(req.getId(), cctv.getSystemId(),
        cctv.getId(), roi.getNo(), pt);
    }

    return req;
  }

  @Test
  public void testProcess(){

    SearchRequest req = this.createAndPersistNewSearchReq();
    SearchTaskProcessor processor = this.spring.getBean(...);

    //...

    processor.process(req.getId(), "1", crtr);
  }
}


In proxy mode
  • Log
Advertisement