is dependency needed to create a spring boot web application?
is dependency needed to create a spring boot web application? Ne90'dan bulabilirsiniz
Creating a Web Application With Spring Boot
This guide will help you create a simple web application with Spring Boot. We will develop a simple application with login functionality as well as the functionality to show a list of todos. We will follow the MVC pattern using JSP as the view.
Overview of the Web Application
We will build a todo list page (un-formatted) with basic login features.
Files
The following screenshot shows an eclipse project with all the files we will create.
A brief overview of all files:
Screenshots of the Application
Login Page
Login Page if user enters invalid user id and password
Welcome Page
List Todos Page
Bootstrapping a Web Application With Spring Initializr
Creating a Web application with Spring Initializr is a cake walk. We will use Spring Web MVC as our web framework.
As shown in the image above, we need to perform the following steps:
Project Dependencies
Spring Boot Starter Web provides all the dependencies and the auto configuration needed to develop web applications. We should use the first dependency.
We want to use JSP as the view. Default embedded servlet container for Spring Boot Starter Web is tomcat. To enable support for JSP’s, we would need to add a dependency on tomcat-embed-jasper.
Spring Boot Starter Web Dependencies
Following screenshot shows the different dependencies that are added into our application because of Spring Boot Starter Web.
Dependencies can be classified into:
Any typical web application would use all these dependencies. Spring Boot Starter Web comes pre-packaged with these. As a developer, I would not need to worry about either these dependencies or their compatible versions.
Auto Configuration
Spring Boot Starter Web auto configures the basic things we needed to get started. To understand the features Spring Boot Starter Web brings in, let's run StudentServicesApplication.java as a Java Application and review the log.
Spring Boot Starter Web auto-configures:
Configuring a View Resolver
We would have our jsp’s in /WEB-INF/jsp/. We would need to configure the view resolver with the prefix and suffix.
Login Controller
Login Service
Has the basic logic for authentication. Hardcoded business logic.
Login View - JSP
Simple login page with user id and password form fields. If an error message is populated into the model, ${errorMessage}
will show the authentication failure error message.
Welcome View - JSP
The welcome page is shown on successful authentication. Shows the name of the login user and a link to manage your todos.
Todo Model and Business Service
We are using a basic todo with id, user, description, and a target date.
Our todo service uses a simple ArrayList to store a list of todos. It offers a method to retrieve the todos.
List Todos - JSP
This is the page that will show our list of todos. This is a completely unformatted page. During the subsequent steps, we will beautify this page and create more functionalities so you can add, delete, and update todos.
Todo Controller
The Todo Controller has a simple method to retrieve the list of todos and populate it into the model. It redirects to the list-todos view.
Running the Application
We use a Spring Boot Application class to launch our application.
The complete code is on my Github repository. You can download Step12.zip and import it as a Maven project to be able to run it.
You can run this as a simple Java application. When you run this you should see the application starting up. Below is some of the extracts from the log. You can see that all the request mappings are properly mapped. You can launch the application at http://localhost:8080/login and enter user id/password combination of in28Minutes/dummy.
Yazı kaynağı : dzone.com
Building an Application with Spring Boot
Projects
Training
Support
Thank You
Yazı kaynağı : spring.io
Spring Boot Starter Web
Our Services
Website Development
Android Development
Website Designing
Digital Marketing
Summer Training
Industrial Training
College Campus Training
Yazı kaynağı : www.javatpoint.com
Spring Boot - Securing Web Applications
Spring Boot - Securing Web Applications
If a Spring Boot Security dependency is added on the classpath, Spring Boot application automatically requires the Basic Authentication for all HTTP Endpoints. The Endpoint “/” and “/home” does not require any authentication. All other Endpoints require authentication.
For adding a Spring Boot Security to your Spring Boot application, we need to add the Spring Boot Starter Security dependency in our build configuration file.
Maven users can add the following dependency in the pom.xml file.
Gradle users can add the following dependency in the build.gradle file.
Securing a Web application
First, create an unsecure web application by using Thymeleaf templates.
Then, create a home.html file under src/main/resources/templates directory.
The simple view /hello defined in the HTML file by using Thymeleaf templates.
Now, create a hello.html under src/main/resources/templates directory.
Now, we need to setup the Spring MVC – View controller for home and hello views.
For this, create a MVC configuration file that extends WebMvcConfigurerAdapter.
Now, add the Spring Boot Starter security dependency to your build configuration file.
Maven users can add the following dependency in your pom.xml file.
Gradle users can add the following dependency in the build.gradle file.
Now, create a Web Security Configuration file, that is used to secure your application to access the HTTP Endpoints by using basic authentication.
Now, create a login.html file under the src/main/resources directory to allow the user to access the HTTP Endpoint via login screen.
Finally, update the hello.html file – to allow the user to Sign-out from the application and display the current username as shown below −
The code for main Spring Boot application is given below −
The complete code for build configuration file is given below.
Maven – pom.xml
Gradle – build.gradle
Now, create an executable JAR file, and run the Spring Boot application by using the following Maven or Gradle commands.
Maven users can use the command as given below −
After “BUILD SUCCESS”, you can find the JAR file under target directory.
Gradle users can use the command as shown −
After “BUILD SUCCESSFUL”, you can find the JAR file under the build/libs directory.
Now, run the JAR file by using the command shown below −
Hit the URL http://localhost:8080/ in your web browser. You can see the output as shown.
Yazı kaynağı : www.tutorialspoint.com
Yorumların yanıtı sitenin aşağı kısmında
Ali : bilmiyorum, keşke arkadaşlar yorumlarda yanıt versinler.