0% found this document useful (0 votes)
3 views

Spring Boot

Uploaded by

Shubham Puri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Spring Boot

Uploaded by

Shubham Puri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Spring Boot

 @Configuration declared class as full configuration class that class must not be final and it must

be public

 @Bean declares bean configuration inside configuration class. It is mostly used on method and

that method must not be private or final

 @Component declared as class level annotation that marks class as spring component and this

class will be marked as spring bean. The class which is denoted by @Component annotation

should be initialized, configured, and managed by spring core container

 If We are not provided name for bean then it will take method name as bean name

 Dependency Injection:

o Constructor Injection===Most Recommended

o Field Injection=====It should not be used

o Configuration Method====We can inject more than one dependency in single method

o Setter Injection

 @Qualifier If there are two beans of same type then we can use @Qualifier annotation for

separate bean by using name and @Qualifier annotation is used along with @Bean annotation.

 @Primary It is used to make bean prioritized. Then the bean with @Primary will be always

injected

 Bean Scoping:

o Default scope of bean is singleton

o Types of scope:

 Singleton =same object will be reused

 Prototype = always new object will be created

 Request

 Session

 Application

 Web socket
o @Scope annotation is used to define scope of the bean.

 @Value annotation is used to assign values to the members of the class through spring expression

language.

 @Autowired: It is used to inject the dependency to component.

 @PropertyResource: It is used to give customize properties path.

 @PropertResources({@PropertyResource(“”),@PropertyResource(“”)}

 @Component: When you want to create a general Spring-managed bean.

 @Repository: Applied to classes which interacts with databases.

 @Service: Applied to class where business logic is written.

 @Controller: Applied to classes where web requests are handeled.

 @Profile(“name”): It is used to decide which profile to be used while injecting.


Spring REST
 REST stands for Representational state transfer

 It supports client server architecture

 Stateless protocol

 HTTP Methods
HTTP Methods Uses
1.GET It is used to retrive data from the server it is read
only operation. It does not affect state of the
resource

2.POST It is used to send data to the server to create new


resource data is included in body of the request

3.PUT This method is used to update the existing resource


or create new resource if does not exist and new
data will be included in the body of request

4.DELETE This method is used to delete the resource


specified by URL

5.PATCH This method is used to apply partial modification in


to the resource

6.OPTIONS This method is used to return HTTP methods that


server supports for specified URL

7.HEAD This method is similar to GET but only returns


header of the response not body

 Status Codes:
o 1XX---------------------------------> INFORMATIONAL

o 2XX--------------------------------->SUCCESS------->200(OK),201(Created)

o 3XX-------------------------------->REDIRECTION

o 4XX-------------------------------->CLIENT ERROR

o 5X----------------------------------->SERVER ERROR
Status Codes Information Code

1XX Informational

2XX Success 200: OK


201: Created
204: No Content

3XX Redirection 304: Not Modified (Caching Purpose)

4XX Client Error 400: Bad Request (server is unable to

understand the request)

401: Unauthorized (Wrong user name and

password)

403: Forbidden (Client does not have

access to the resource)

5XX Server Error

You might also like