Spring Annotations

@SpringBootApplication

@SpringBootConfiguration

@EnableAutoConfiguration

@ComponentScan

@Component for any Spring-managed component, scanned by

to respect the convention:

@Repository for persistence layer – deal with DataAccessException

@Service for service layer

@Controller for presentation layer (spring-mvc) – the dispatcher scans the classes annotated with @Controller and detects @RequestMapping annotations within them. We can only use @RequestMapping on @Controller

@EnableWebMvc

@RestController – The Controller only sends back the model (or resource representation) – @Controller + @ResponseBody

@RequestBody – convert incoming JSON

@ResponseBody – annotation means is that the returned value of the method will constitute the body of the HTTP response of accounts is transformed to a format suitable for REST applications, typically JSON or XML

@RequestMapping – mapping web requests onto methods in request-handling classes (produces = MediaType.APPLICATION_JSON_UTF8_VALUE)

@RunWith

@SpringBootTest

@AutoConfigureMockMvc

@Transactional – start transaction (see Transaction propagations in Spring)

@ModelAttribute

@PathVariable

@Scope

@PostConstruct

@PreDestroy

@Profile

Transaction propagations in Spring

Defaults to Propagation.REQUIRED

TransactionDefinition.ISOLATION_DEFAULT – Use the default isolation level of the underlying datastore.
TransactionDefinition.ISOLATION_READ_COMMITTED – Indicates that dirty reads are prevented; non-repeatable reads and phantom reads can occur.
TransactionDefinition.ISOLATION_READ_UNCOMMITTED – Indicates that dirty reads, non-repeatable reads and phantom reads can occur.
TransactionDefinition.ISOLATION_REPEATABLE_READ – Indicates that dirty reads and non-repeatable reads are prevented; phantom reads can occur.
TransactionDefinition.ISOLATION_SERIALIZABLE – Indicates that dirty reads, non-repeatable reads and phantom reads are prevented.

TransactionDefinition.PROPAGATION_MANDATORY – Support a current transaction; throw an exception if no current transaction exists.
TransactionDefinition.PROPAGATION_NESTED – Execute within a nested transaction if a current transaction exists, behave like PROPAGATION_REQUIRED else.
TransactionDefinition.PROPAGATION_NEVER – Do not support a current transaction; throw an exception if a current transaction exists.
TransactionDefinition.PROPAGATION_NOT_SUPPORTED – Do not support a current transaction; rather always execute non-transactionally.
TransactionDefinition.PROPAGATION_REQUIRED – Support a current transaction; create a new one if none exists.
TransactionDefinition.PROPAGATION_REQUIRES_NEW – Create a new transaction, suspending the current transaction if one exists.
TransactionDefinition.PROPAGATION_SUPPORTS – Support a current transaction; execute non-transactionally if none exists.

TransactionDefinition.TIMEOUT_DEFAULT – Use the default timeout of the underlying transaction system, or none if timeouts are not supported.

@Transactional (rollbackFor=Exception.class)
@Transactional (noRollbackFor=IllegalStateException.class)

XA transaction implementation: JTA – Java Transaction API

JTA – Java Transaction API | ACID | Two-phase commit | Three-phase commit

XA-compliant

javax.transaction
javax.transaction.xa

javax.transaction.TransactionManager
javax.transaction.UserTransaction
javax.transaction.xa.XAResource

UserTransaction.begin() – start transaction associated to thread

@Transactional
@TransactionScoped

https://www.progress.com/tutorials/jdbc/understanding-jta

Spring Test DBUnit

gradle:

 

Spring Security

Spring Security is a framework that focuses on providing both authentication and authorization to Java applications.