Creation, operation and configuration of Java EE development springboot Project

Source: Internet
Author: User

Software 152 Lu Renshun

This blog we'll talk about how to use the Eclipse+sts plugin to create a spring boot project. Spring boot can make it easier to use the spring framework and automatically configure a lot of things in spring boot, which saves us a lot of work. Today we'll create a spring boot project, then create a test controller on the project and configure the appropriate route, and finally we'll look at the effect. Of course, we'll talk about how to configure Spring Boot for this blog post.

In the spring boot project, there is a application.properties file that resembles the Info.plist in iOS development to hold some configuration properties. We'll take a look at this blog post today to see how these things are implemented.

First, create and run the spring Boot

In the fourth part of a previously published blog, the Eclipse-based environment for Java EE Development and the creation of Maven Web app, we talked about how to install the Sts--spring Tools suite (Spring tools suite), We'll use the kit to create the Spring boot project and give it some work. Spring boot allows us to develop Java EE projects quickly and easily using other Maven-managed third-party libraries such as spring. After installing the STS in Eclipse, you can quickly create a spring project.

1. Create Spring Boot Project

First we open the Select Project template page via file->new->other .

  

Then we find the spring Starter project option under the Spring module and click Next. The Spring Starter project here is a typical spring boot project.

  

Enter the appropriate information for the project, such as the package name, organization name, and so on, as follows:

  

After clicking Next on the previous step, go to the dialog box below. From below we can quickly add a few dependent libraries. The dependent libraries we choose here are web only. After selecting the library that the project relies on, the project will automatically introduce the corresponding dependencies for us. Click Finish.

  

2. Create Indexcontroller

After the above steps, our Spring boot project is created. Next we create a indexcontroller and configure the appropriate routes so that we can test them for access. The directory below is the spring boot directory we created. The Startspringbootdemoapplication.java is primarily used to load auto-configuration items for spring boot, and it is also an automatically created file in the project.

  

The above-mentioned Indexcontroller is created by ourselves, and the code in Indexcontroller is relatively simple, which is a common controller in spring. The "/" route is configured, and a "Welcome Spring Boot" string is returned when the "/" route is accessed. The specific code is shown below.

  

3. Run the above project

After the Indexcontroller class is created, we can run tests on the project. We can run the project by using the Spring Boot App , run as. as shown below.

  

After running, the console will output the log below. From the log below, it is not difficult to see that we are using spring-boot v1.5.2 here.

  

After the run is complete we can access it in the browser, the default access port is 8080. Below are the specific results for the routing access we configured above, as follows:

  

Second, the Spring boot configuration

There is a application.properties file under src/main/resources in the Spring boot project where we can add configuration properties to spring boot. In fact, this application.properties file is very similar to the Info.plist file in iOS development, and its function is to provide configuration items for some configuration projects. In spring boot we can add the entire project's configuration to the file. Below is what we did when we configured the server.

  

We can change the access port to 9090 as shown below. After adding the configuration item below, we can use port 9090 to access our project.

  

We can also make the appropriate configuration for different environments. This means that we can create multiple profiles and then activate them in application.properties. The application-dev.properties and application-prod.properties below are our newly created two configuration files, one to store configuration properties in the development environment, and the other to store configuration properties in the production environment.

  

We can specify that the configuration file be loaded in the Application.properties file as follows:

spring.profiles.active=Dev

Creation, operation and configuration of Java EE development springboot Project

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.