Fortress Java Learning Portal

Spring Framework • MVC • Configuration • Spring Boot

Spring Basic Annotations

Fortress Java Learning Portal format

This page preserves the terminology and organization of the uploaded source. The source covers Spring annotations, configuration, dependency injection, Spring Boot basics, MVC/Web, Cloud and related concepts.

Source Page 1

annotations cheat sheet

Spring Boot and Web annotations

Use annotations to configure your web application.

@SpringBootApplication - uses @Configuration,
@EnableAutoConfiguration and @ComponentScan.
@EnableAutoConfiguration - make Spring guess the

configuration based on the classpath.

@Controller - marks the class as web controller, capable

of handling the requests. @RestController - a convenience

annotation of a @Controller and @ResponseBody.

@ResponseBody - makes Spring bind method’s return

value to the web response body.

@RequestMapping - specify on the method in the

controller, to map a HTTP request to the URL to this method.

@RequestParam - bind HTTP parameters into

method arguments.

@PathVariable - binds placeholder from the URI

to the method parameter.

Spring Framework annotations

Spring Cloud annotations

Make you application work well in the cloud.

@EnableConfigServer - turns your application into

a server other apps can get their configuration from.

Use spring.application.cloud.config.uri in the client

@SpringBootApplication to point to the config server.
@EnableEurekaServer - makes your app an Eureka

discovery service, other apps can locate services through it.

@EnableDiscoveryClient - makes your app register in the

service discovery server and discover other services through it.

@EnableCircuitBreaker - configures Hystrix circuit

breaker protocols.

@HystrixCommand(fallbackMethod =

“fallbackMethodName”) - marks methods to fall back

to another method if they cannot succeed normally.

Spring uses dependency injection to configure and bind

your application together.

@ComponentScan - make Spring scan the package

for the @Configuration classes.

@Configuration - mark a class as a source of

bean definitions.

@Bean - indicates that a method produces a bean to be

managed by the Spring container.

@Component - turns the class into a Spring bean at the

auto-scan time. @Service - specialization of the

@Component, has no encapsulated state.
@Autowired - Spring’s dependency injection wires

an appropriate bean into the marked class member.

@Lazy - makes @Bean or @Component be initialized

on demand rather than eagerly.

@Qualifier - filters what beans should be used to
@Autowire a field or parameter.
@Value - indicates a default value expression for

the field or parameter, typically something like

“#{systemProperties.myProp}”

@Required - fail the configuration,

if the dependency cannot be injected.

For more awesome cheat sheets

visit rebellabs.org!

Legend

  • class
  • field annotation
  • constructor annotation
  • method
  • parameter
@SpringBootApplication

HTTP Responses

@RestController
@Autowired
Service service;
@RequestMapping

public Map serveRequest()

@Configuration
@Bean

public MyBean

provideBean()

@Service
@Component

provides

beans

like these

beans

are

injected

Cloud

Configuration

server

Service

discovery

asks

configuration

receives

properties

asks services

location

receives URL

registers itself

as a service

HTTP Requests

T
F
C
M
P
F
C
M
F
C
M
F
C
M

T M

F
C
M
T
T
M
T
T
T
M
T
T
T
T
M
T
P
T
T
T
T
M
P

Original Visual Reference

The original PDF contains architecture/annotation diagrams. They are retained below for visual reference.

View original visual — Page 1Original PDF page 1