idea creates maven's springboot project

Posted by l9pt5 on Sat, 01 Feb 2020 05:52:48 +0100

1. Create a project:

1. Create a new project:

2. Click next

3. Choice dependency:

Select a web project here

4. Customize the project name and path:

The structure path of the created project is as follows:

Project Start:

Click Run to run

The startup log is as follows:

Indicates that the operation was successful.

Access localhost:8080

Display:

Indicates that the project was created successfully

2. Write a controller test

Create a demoController:

The demoController code is as follows:

@RestController
public class DemoController {

    @RequestMapping("test")
    public String demoTest(){
        return "test";
    }
}

Start DemoApplication again, after successful startup, visit http://localhost:8080/test

Show as test, indicating that the controller was created successfully

At this point, project creation and controller testing have succeeded

By habit, I like to start projects with idea external tomcat

3. Transform the project into one started by idea external tomcat

Refer to this article: https://blog.csdn.net/afadasdas/article/details/99200543

1. In pom.xml settings:

 <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
            </plugin>
        </plugins>
        <finalName>springbootdemo</finalName>
    </build>

2. Remove dependency on embedded Tomcat in SpringBoot

Delete the class shown above

And add in the pom file:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

3. Modify the startup class:

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(DemoApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

4. Startup project through tomcat found errors at startup:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path resource

Check it online because the springboot version is too high

Manually reduce springboot version to 1.5.9.RELEASE

In the pom file:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

Last Start Successful

The third part refers to foreign articles, the article links are given, and the articles cited explain how to configure tomcat and tomcat startup

 

31 original articles published, 8 praised, 8552 visited
Private letter follow

Topics: Tomcat SpringBoot Apache Maven