JWT stands for JSON Web Token. JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. The client will need to authenticate with the server using the credentials only once. During this time the server validates the credentials and returns the client a JSON Web Token(JWT). For all future requests the client can authenticate itself to the server using this JSON Web Token(JWT) and so does not need to send the credentials like username and password.
Posted Date:- 2021-08-25 00:53:05
Thymeleaf is a server-side template engine for a web application. Its main purpose is to bring natural templates to the web application.
Specifically, one has to include the dependency spring-boot-starter-thymeleaf in the application to use thymeleaf.
Posted Date:- 2021-08-25 00:51:27
To disable any specific auto-configuration, one can use exclude attribute for @EnableAutoConfiguration annotation.
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
public class SampleApplication
{
}
Posted Date:- 2021-08-25 00:50:08
For applications to use auto-configuration, component scans, and extra configurations, one can include one single annotation @SpringBootApplication. This annotation includes three annotations @EnableAutoConfiguration, @ComponentScan, and @Configuration.
@EnableAutoConfiguration – enable Spring Boot’s auto-configuration
@ComponentScan – this allows scanning the packages where the application is located.
@Configuration – allow registering extra beans in the context or import additional configuration classes.
Posted Date:- 2021-08-25 00:49:17
By default, the Spring Boot application runs on HTTP port. To make your application run with HTTPS port, there are two ways.
One can use server.port, server.ssl.key-store-password,server.ssl.key-store ,server.ssl.key-store-type and server.ssl.key-alias.
Another way to use the HTTPS port is programmatically.
Posted Date:- 2021-08-25 00:48:04
Spring Boot Actuator can provide that information, through HTTP or JMX endpoints. Alternatively, you can start-up your Spring Boot application with the "--debug" flag.
Do note, that the information on evaluated conditions is a bit "raw" and not easily digested. For that, read this guide to make sure you understand how Spring Boot’s auto-configurations work.
Posted Date:- 2021-08-25 00:46:58
The simplest way to deploy your Spring Boot application is as a .jar file with an embedded servlet container, to any server or platform that has a JRE installed.
For organizational and historical reasons, you can also deploy your Spring Boot application as a .war file, into an existing servlet container or application server.
Last but not least, you can, of course, also put your .jar file into a Docker image and even deploy those with Kubernetes.
Posted Date:- 2021-08-25 00:46:21
This is because Spring Boot does some dependency management for you.
On a high-level, Spring Boot starters pull-in a parent pom.xml file (or a build.gradle file) which has all the dependencies and respective versions defined that a specific Spring Boot version supports - a so-called bill of materials. You can then simply use those pre-defined versions, or override the version numbers in your own build scripts.
You can find the list of all currently supported 3rd party libraries and versions in the spring-boot-dependencies project.
Posted Date:- 2021-08-25 00:43:35
You can create new Spring Boot projects through the Spring Initializr web application or the Spring Boot CLI. Interestingly enough, Spring Initializr is not just a website where you can generate project skeleton .zip files. It is also an API, that you can programmatically call. All major IDEs (Spring Tool Suite, IntelliJ IDEA Ultimate, Netbeans and VSCode) directly integrate with it, so that you can create new Spring Boot projects right out of your IDE.
As for starters, you need to read the documentation and have a bit of experience. If working with a web application, you will start with spring-boot-starter-web and then add the appropriate starter from the documentation, once you want to include a certain technology. After a while, you will get a good feel for what starters you need for which technologies.
Posted Date:- 2021-08-25 00:39:34
Primarily used for developing microservices-based applications, Spring Boot offers the following key features for configuring, developing, and deploying microservices architecture.
Integrates a tool called the Actuator, which enables users to manage and monitor applications
Provides support for embedded servers, such as Jetty and Tomcat
Users can simply run war files, without deploying it
Includes an Auto-Configuration functionality, allowing users to configure Spring applications automatically
Supports HTTP client Feign
Posted Date:- 2021-08-25 00:38:03
You will find the class files ${basedir}/target/classes/.
Posted Date:- 2021-08-25 00:36:27
Usually an artifact is a JAR file which gets arrayed to a Maven repository. One or more artifacts a maven build produces such as compiled JAR and a sources JAR.
Each artifact includes a group ID, an artifact ID and a version string.
Posted Date:- 2021-08-25 00:35:21
Maven is a project management tool. It provides the developer a complete build lifecycle framework. On executing Maven commands, it will look for POM file in Maven; it will run the command on the resources described in the POM.
Posted Date:- 2021-08-25 00:34:28
Aspect Oriented Programming (AOP) supplements Object-Oriented Programming (OOP) by giving another mindset about program structure. The key unit of measured quality in OOP is the class, while in AOP the unit of particularity is the viewpoint. Angles empower the modularization of concerns, for example, transaction management that cut over numerous sorts and questions.
Posted Date:- 2021-08-25 00:33:35
Few are the important features in Spring Boot
Spring initializer
Starter dependency
Auto-configuration
Posted Date:- 2021-08-25 00:31:31
It takes after "Opinionated Defaults Configuration" Approach to lessen Developer exertion. Because of the Opinionated perspective of spring boot, what is required to begin yet additionally we can get out if not appropriate for the application. Spring Boot utilizes sensible defaults, “opinions,” for the most part in light of the classpath substance.
Posted Date:- 2021-08-25 00:30:41
Starters are an arrangement of advantageous reliance descriptors that you can incorporate into your application. The starters contain a considerable amount of the dependencies that you have to get a task up and running rapidly and with a steady, supported a set of managed transitive conditions.
The starter POMs are helpful reliance descriptors that can be added to your application’s Maven. In another word, if you are building up a project that utilizes Spring Batch for batch preparing, you need to incorporate spring-boot-starter-bunch that will import all the required conditions for the Spring Batch application. This decreases the burden of looking at and designing all of the conditions required for a structure.
Posted Date:- 2021-08-25 00:29:28
Spring Data REST is not recommended in real-world applications as you are exposing your database entities directly as REST Services. While designing RESTful services, the two most important things that we consider is the domain model and the consumers. But, while using Spring Data REST, none of these parameters are considered. The entities are directly exposed. So, I would just say, you can use Spring Data REST, for the initial evolution of the project.
Posted Date:- 2021-08-25 00:28:42
Create a folder and name it static under the resources folder and you can put the static content in that folder. Just in case, the browser throws an unauthorized error, you either disable the security or search for the password in the log file, and eventually pass it in the request header.
Posted Date:- 2021-08-25 00:27:59
Below are the steps to deploy application on virtual machine.
a). Install Java.
b). Install the Application Server.
d). Deploy the application war file.
Posted Date:- 2021-08-25 00:27:16
When we use the Spring Boot Auto Configuration, automatically the spring-boot-starter-data-jpa dependency gets added to the pom.xml file. Now, since this dependency has a transitive dependency on JPA and Hibernate, Spring Boot automatically auto-configures Hibernate as the default implementation for JPA, whenever it sees Hibernate in the classpath.
Posted Date:- 2021-08-25 00:26:10
The advantages of the YAML file than a properties file is that the data is stored in a hierarchical format. So, it becomes very easy for the developers to debug if there is an issue. The SpringApplication class supports the YAML file as an alternative to properties whenever you use the SnakeYAML library on your classpath. The different ways to load a YAML file in Spring Boot is as follows:
1. Use YamlMapFactoryBean to load YAML as a Map
2. Use YamlPropertiesFactoryBean to load YAML as Properties
Posted Date:- 2021-08-25 00:25:09
Yes. It is possible to exclude package without using the basePackages filter by simply using the exclude attribute while using the @SpringBootApplication annotation.
Posted Date:- 2021-08-25 00:21:21
Follow the following methods to set an active profile in Spring Boot.
1. Pass this profile as an argument when you launch the Spring Boot application.
2. Set active the active profile in application.properties file.
Posted Date:- 2021-08-25 00:19:40
A class without any package declaration is considered as a default package.
Posted Date:- 2021-08-25 00:17:41
When developing applications for the enterprise, we typically deal with multiple environments such as Dev, QA and Prod. The configuration properties for these environments are different.
For example, we might be using an embedded H2 database for Dev, but Prod could have the proprietary Oracle or DB2. Even if the DBMS is the same across environments, the URLs would definitely be different.
To make this easy and clean, Spring has the provision of profiles to help separate the configuration for each environment. So, instead of maintaining this programmatically, the properties can be kept in separate files such as application-dev.properties and application-prod.properties. The default application.properties points to the currently active profile using spring.profiles.active so that the correct configuration is picked up.
Posted Date:- 2021-08-25 00:16:59
To deploy a different server with Spring Boot: Generate a WAR from the project and then, deploy the WAR file onto your favorite server. The steps to deploy the WAR file on the server is dependent on the server you choose.
Posted Date:- 2021-08-25 00:16:19
while a Spring Boot app is executed as “Run as Java Application, then it routinely launches up the tomcat server and deploys the application automatically.
Posted Date:- 2021-08-25 00:15:47
Spring boot has a very useful way to do this. ControllerAdvice used to handle exceptions in Spring Boot. This will be implemented everywhere where it handles all exceptions thrown by the controller class.
Posted Date:- 2021-08-25 00:14:55
Example for ReadOnly as TRUE in transaction management could be as follows: Consider a scenario, where you have to read data from the database. For example, let us say you have a customer database, and you want to read the customer details such as customerID, and customername. To do that, you will set read-only on the transaction as we do not want to check for the changes in the entities.
Posted Date:- 2021-08-25 00:14:24
CORS stands for Cross-Origin Resource Sharing is a mechanism implemented by browsers and helps users to authorize cross-domain requests. This mechanism serves as an alternative to less secure and less powerful hacks of the kinds of IFrame or JSONP.
Posted Date:- 2021-08-25 00:13:19
Freemarker is a Java-based template used to generate plain text, emails, HTML file, etc.
Posted Date:- 2021-08-25 00:12:54
Cross-Site Request Forgery attack or one-click attack is an attack that forces other users to execute malicious commands on the application. CSRF attack specifically targets state-changing requests.
Posted Date:- 2021-08-25 00:12:28
The major strong point in Spring is to provide flexibility to build your application loosely coupled. Spring provides features to disable the web server in a quick configuration. Yes, we can use the application.properties to configure the web application type, i.e. spring.main.web-application-type=none.
Posted Date:- 2021-08-25 00:11:36
Yes, it's possible to change the port. You can use the application.properties file to change the port. But you need to mention "server.port" (i.e. server.port=8081). Make sure you have application.properties in your project classpath; REST Spring framework will take care of the rest. If you mention server.port=0 , then it will automatically assign any available port.
Posted Date:- 2021-08-25 00:10:41
Shutdown is an endpoint that allows the application to be gracefully shutdown. This feature is not enabled by default. You can enable this by using management.endpoint.shutdown.enabled=true in your application.properties file. But be careful about this if you are using this.
Posted Date:- 2021-08-25 00:10:00
The ELK Stack is made of three open-source products: 1) Elasticsearch, 2) Logstash, and 3) Kibana.
1) Elasticsearch: It is a NoSQL database which is based on the open-source search engine called Lucene.
2) Logstash: It is a data processing pipeline tool which accepts inputs from sources, performs different transformations, and exports the data to targets.
3) Kibana: Kibana helps users to visualize data with graphs and chart in Elasticsearch.
Posted Date:- 2021-08-25 00:09:20
It is a tool designed to create, deploy, and run a project by using containers.
Posted Date:- 2021-08-25 00:08:21
Spring Boot has lots of properties that can be easily overridden by specifying them in application.properties.
Posted Date:- 2021-08-25 00:07:53
In order to enable debug logging, you can specify --debug while starting the application from the command prompt.
Posted Date:- 2021-08-25 00:07:25
The @Grab annotation is used to import types which Spring boot CLI cannot resolve automatically. It actually extends @Grab annotation from Gradle, a JAR dependency manager into Groovy, so that, for many frequently used library you can import them by just adding module ID like you can just write @Grab("h2") instead of @Grab("com.h2database:h2:1.4.185) to import H2 in-memory database and Spring CLI will take care of version, etc.
Posted Date:- 2021-08-25 00:05:50
Yes, Spring Boot CLI makes it possible to write Spring Boot application in Groovy. It also cut down a lot of noise which comes with writing code in Java.
Posted Date:- 2021-08-25 00:05:21
Just like Spring MVC application, you can secure the Spring Boot Actuator's endpoints using Spring Security. You can add a Security starter as a build dependency and then security auto-configuration will take care of locking the application, including the Actuator endpoints.
Posted Date:- 2021-08-25 00:04:57
The primary annotations that Spring Boot offers reside in its org.springframework.boot.autoconfigure and its sub-packages.
Here are a couple of basic ones:
@EnableAutoConfiguration – to make Spring Boot look for auto-configuration beans on its classpath and automatically apply them
@SpringBootApplication – to denote the main class of a Boot Application. This annotation combines @Configuration, @EnableAutoConfiguration and @ComponentScan annotations with their default attributes.
Posted Date:- 2021-08-25 00:03:06
Auto-configuration is used to configure Spring application automatically based on dependencies of classpath parameter. It makes development faster and easier.
Posted Date:- 2021-08-25 00:00:17
Relaxed binding, is a way in which, the property name does not need to match the key of the environment property. In Spring Boot, relaxed binding is applicable to the type-safe binding of the configuration properties. For example, if a property in a bean class with the @ConfigurationPropertie annotation is used sampleProp, then it can be bounded to any of the following environment properties:
a) sampleProp
b) sample-Prop
c) sample_Prop
d) SAMPLE_PROP
Posted Date:- 2021-08-24 23:59:43
The dependencies are needed to start up a JPA Application and connect to in-memory database H2 with Spring Boot
web starter
h2
data JPA starter
To include the dependencies refer to the following code:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Posted Date:- 2021-08-24 23:57:19
There are different ways you can filter any package. But Spring Boot provides a trickier option for achieving this without touching the component scan. You can use the exclude attribute while using the annotation @SpringBootApplication. See the following code snippet:
@SpringBootApplication(exclude= {Employee.class})
public class FooAppConfiguration {}
Posted Date:- 2021-08-24 23:55:55
If H2 is not present in the classpath, then you see the following error:
To resolve this error, add H2 to the pom.xml file, and restart your server.
The following code snippet can be added to add the dependency:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
Posted Date:- 2021-08-24 23:54:36
To instruct an auto-configuration class to back off when a bean exists, you have to use the @ConditionalOnMissingBean annotation. The attributes of this annotation are as follows:
a) value: This attribute stores the type of beans to be checked
b) name: This attribute stores the name of beans to be checked
Posted Date:- 2021-08-24 23:53:51