-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnnotations
More file actions
65 lines (43 loc) · 3.7 KB
/
Annotations
File metadata and controls
65 lines (43 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Spring Boot is a tool to develop spring based enterprise applications. And its opinionated (boot with recommendation), offers opinionated run time for spring (opinions can be overridden)
Convention, not configuration
Simple dependency management
Setup a maven project
Configure pom.xml to include the parent and dependency tags
@SpringBootApplication is the annotation used in the main class to indicate that it’s a spring boot application
SpringApplication.run(App.class, arg) initiates the bean injection
BOM - BILL OF MATERIAL in Spring Boot is the list of all Jar's that are required to run the application without issues.
Spring Boot has tomcat server embedded in it and its configuration is available in application configuration (no server configuration exist), this makes spring boot a stand alone
Buisness Services in Spring are technically singleton
@Service marks a class as business Service that serve a controller class
@AutoWired - injects the Bean class into your Bean
@RequestMapping - maps the request to a resource
@RestController - a class a controller that manages the resources and bean injection
JPA(Java Persistence API) is used to do ORM(Object - Relational Mappixng)
@Entity - denotes a class as entity class
@ID - denotes a Field as primary Key
@ManyTOOne - denoates a relation ship table
Maven Build To Deploy the Application
We don’t need a servlet containers like tomcat to run the spring boot application just a jar
Embeds app server in executable jars
To get Jar by Maven build in cmd line use this cmd - mvn clean install
To run the spring boot Use the cmd - java -jar target/(specify the jar obtained in the the above)
Adding a dependency for actuator in the pom.xml enables the spring boot application to be monitored for different metrics.
Actuator Is a build in endpoints for health Metrics.
Example you can examine the beans list all the beans and its scope
In the example application, we have these Spring Boot annotations:
• @Bean - indicates that a method produces a bean to be managed by Spring.
• @Service - indicates that an annotated class is a service class.
• @Repository - indicates that an annotated class is a repository, which is an abstraction of data access and storage.
• @Configuration - indicates that a class is a configuration class that may contain bean definitions.
• @Controller - marks the class as web controller, capable of handling the requests.
• @RequestMapping - maps HTTP request with a path to a controller method.
• @Autowired - marks a constructor, field, or setter method to be autowired by Spring dependency injection.
• @SpringBootApplication - enables Spring Boot autoconfiguration and component scanning.
@Component is a generic stereotype for a Spring managed component. It turns the class into a Spring bean at the auto-scan time. Classes decorated with this annotation are considered as candidates for auto-detection when using annotation-based configuration and classpath scanning.@Repository, @Service, and @Controller are specializations of @Component for more specific use cases.
There are also Hibernate @Entity, @Table, @Id, and @GeneratedValue annotations in the example.
@ResponseBody - tells dispatchservlet to not to look for view to return value but directly retunrn the value to the browser (need definition from web)
@ComponentScan - searches for components within the package specified , this is called component Scan
ViewResolver - dispatch servlet uses view resolver to resolve the view path, view resolver is configured in application.properties
@SessionAttribute - for conversational storage(value persist across multiple request)
Jasper is the dependency needed to be added for JSP
Dispatcher Servlet is called Front Controller