Explain in detail how to transform an existing project into a spring boot project
Quickly create a springboot web project
Take IntelliJ idea as an example:
1. First create a project, select spring initializr and then next, as shown in the following figure:
2. Fill in the project information, as shown in the figure below:
3. Check Web
4. Finally, fill in the project name and click finish
The system will download the required dependencies during the first creation, which takes a little longer. Please wait patiently.
After successful creation, the directory structure is as follows: under the root directory of the project, there will be an entry class of artifactid + application naming rules, springbootlearningapplication
The springbootlearningapplication class has a @ springbootapplication annotation, which is the core annotation of the whole spring boot. Its purpose is to enable the automatic configuration of spring boot.
@Restcontroller annotation to change it into a controller, and then provide an address translation method in it, as follows:
In the main method, right-click and select run. After the project is started, you can access it directly in the browser.
The access path is http://localhost:8080 。
Tip:
If it is created for the first time, you will find that there is a red circle on the file, and the file content cannot be changed. Set as follows:
How to transform an existing project into a spring boot project
1 create a deployable war file
The first step in generating a deployable war file is to create a subclass of springbootservletinitializer and rewrite its configure method. In this way, you can take advantage of the support of spring servlet 3.0 and allow you to configure your application when the servlet container starts. Usually, the class where the main method is located needs to inherit
SpringBootServletInitializer:
The next step is to update the build configuration so that your project generates a war file instead of a jar file. If you use Maven and use spring boot starter parent (which configures Maven's war plug-in for you), all you need to do is modify the pom.xml file to change the project to a war project:
If you use gradle, you need to modify build Gradle to use the war plug-in in the project:
The final step is to ensure that the built-in servlet container does not interfere with the servlet container where the war file is to be deployed. To do this, you need to declare the built-in servlet container dependencies in the given way.
Maven:
Gradle:
[note]
If you are using a version of gradle that only supports compile only dependencies (version 2.12 or later), you should continue to use providedruntime. Within some other restrictions, if the compileonly dependency is not in the path of the test class, this will cause any web-based integration tests to fail.
If you use the spring boot build tool, marking the built-in servlet container dependency as provided will generate an executable and package the provided dependency lib provided in the directory. This means that in addition to being deployed to a servlet container, you can also use the command line running the application Java jar.
Original English Address: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html#howto -convert-an-existing-application-to-spring-boot