[Java] Learning Java framework #1 (Mac version)

3 minute read

Development using Java framework

First of all, open this Eclipse screen.

Screenshot 2020-07-12 4.36.31.png

I will make it where it is painted black. (I hide it because I made it first because I painted it black.)

Next, right-click on the Project Eclipse Roller and select New, Other.

Screenshot 2020-07-12 4.50.45.png

Screenshot 2020-07-12 4.50.54.png

The screen for selecting the weather appears. By the way, this time, Eclipse 2020 I am using the version.

Screenshot 2020-07-12 4.51.08.png

Then select the Spring Starter Project.

Screenshot 2020-05-24 6.13.45.png

Write the package name and name. (The package name and name are all right!)

Screenshot 2020-05-24 6.14.01.png

Now let’s move on to the Spring Starter/Dependencies.

Screenshot 2020-05-24 6.16.01.png

Spring Boot DevTools MyBatis Framework MySQL Driver Spring Security Thymeleaf Spring web Select and click Finish.

Screenshot 2020-05-24 6.28.10.png

Click Finish as it is on the next screen.

Screenshot 2020-05-24 6.28.33.png

When completed, the project is created in the project explorer on the first screen. (Please ignore the projects below as they are not relevant.)

Screenshot 2020-07-12 5.53.43.png

I want to go to the point where the Web application can be started, so I have to make some settings before that, so I will proceed based on the explanation.

First of all, since it is necessary to tell Tomcat of the application server about the connection information with MySQL, at the time of creating the Spring Starter Project project, the source file is already in the source main and the property file called application property under the resource is. there is.

Screenshot 2020-05-25 4.55.39.png

Describe the connection settings with the database here. (It is better to remember the code) For the setting, write the code according to your own environment setting.

Screenshot 2020-05-25 5.04.39.png

You also have to set Spring security, so you have to set it.

Screenshot 2020-05-25 5.07.14.png

Since it can be set in Java class, that method is used.

Screenshot 2020-05-25 5.08.31.png

When creating a new class, please decide the class name as you like.

Screenshot 2020-05-25 5.09.30.png

Screenshot 2020-05-25 5.10.11.png

Screenshot 2020-05-25 5.11.13.png

Once you have filled in your name, click on the superclass reference.

Screenshot 2020-05-25 5.11.57.png

It inherits Spring’s built-in web security, the Comfy Gear Adapter. Click to select, then click OK.

Screenshot 2020-05-25 5.13.42.png

Just click Finish.

Screenshot 2020-05-25 5.14.23.png

Regarding the code, “This is it! Because it is difficult to explain in detail, it’s better to learn it while writing.

Screenshot 2020-05-25 5.15.02.png

First of all, the class that performs the configuration has an annotation called Enable Web Security.

Screenshot 2020-05-25 5.18.11.pngI’m overloading the Comfy Gear method from the super class Web Security Comfy Gear method. There are several Comfy Gear methods, but there are some uses, but this time I just want to start it, so I’m just going to use the authentication manager Overrides the configure method that takes a builder argument and the configure method that takes an HTTP security object as an argument.

Screenshot 2020-05-25 5.18.11.png

Screenshot 2020-05-25 5.35.50.png

This is done.

Screenshot 2020-05-25 5.39.14.png

There is no problem if you consider the Confugia method that takes an object called the Authentication Manager Builder as an argument to determine the recognition method of the user.

There is an authentication method that uses DB (database) to manage user information and LDAP (Lightweight Directory Access Protocol), but this time we will use the database. I just want to operate it easily, so I will set it in memory.

Screenshot 2020-07-20 8.25.18.png

Screenshot 2020-07-20 8.25.29.png

If you can do this, then create a new HTML file from here and elsewhere. (Because I could not put it well, please omit it and put it as the HTML file name index.html.)

Screenshot 2020-07-20 8.38.53.png

OK if done like this

Screenshots 2020-07-20 8.41.30.png

Next, create a controller class.

Screenshot 2020-07-20 8.45.47.png

If you can create it with a class name like this, Ok (Because I made it first, don’t make a mistake)

Screenshot 2020-07-20 8.46.35.png

After writing the code like this, we’re ready to launch the web application.

Screenshots 2020-07-20 8.47.53.png

Then use Spring boot to start the application.

Screenshot 2020-07-20 10.19.15.png

Tomcat has started

Screenshot 2020-07-20 10.22.30.png

Next, let’s see it on the browser.

Screenshot 2020-07-20 10.39.17.png

If you enter the password you decided earlier here

Screenshot 2020-07-20 10.43.17.png

It opens like this.

Screenshot 2020-07-20 10.44.15.png

You could make Spring boot and Spring security together.

I wrote it like this, but (I think it may be a little different) I have a video that you refer to, so I think it will be easier to understand while making it while watching this.

YouTube

TechShare channel

https://www.youtube.com/watch?v=IWH_EZwQhSY&t=1136s

Tags:

Updated: