SpringBoot very fast novice introductory tutorial and complete development step Demo

1. Visit http://start.spring.io/

   Select the build tool Maven Project, Spring Boot version 1.5 and basic information of some projects (check Spring Web), and click "Switch to the full version.".
   
   Click Generate Project to download the project compression package and decompress it
   
2. Open Eclipse (the latest version is recommended), Import -> Existing Maven Projects -> Next -> select the project folder just decompressed -> Finsh

   After that, maven will automatically download the relevant dependency packages, wait for 5 to 30 minutes (no way, Tianchao Network has external control), and wait until the background related progress reaches 100% before starting to work.

3. Modify src/main/resources/application.properties

   Add server.port=9080. The default is 8080.

    打开 porm.xml 找到
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        
    修改为(Web方式启动 )
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>      


4. Add three files under the src/main/resources/static directory: 500.html, 01.html, 04.html

5. Modify the code of DemoApplication.java that comes with it to be as follows

----------------------------------------------------

@SpringBootApplication
public class DemoApplication {

    @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer() {

       return (container -> {
            ErrorPage error01Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/01.html");
            ErrorPage error04Page = new ErrorPage(HttpStatus.NOT_FOUND, "/04.html");
            ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html");

            container.addErrorPages(error01Page, error04Page, error500Page);
       });
    }
    
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
        //System.out.println
    }
    
}


@RestController
class HelloWorldController {//This class can be moved out and become a separate file. Different versions of spring boot seem to have storage requirements.
    
    @RequestMapping("/hello")
    public String index() {         int n = 0;          // n = 1 / n                  return "Hello你好";     } }




----------------------------------------------------

F11 runs (DemoApplication). Visit localhost:9080/hello to see the effect.


6, JAR mode step by step execution

1) Add jar plugin in pom.xml

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-jar-plugin</artifactId>
     <version>2.5</version>
 </plugin>
 
 
2) In E:\PROJECT3\springbootTest Under the directory, shift+right click, "Open the command window here"

Enter the command: mvn install or mvnw install

The first run will load third-party packages, and compile and package

7. After install runs successfully, a target directory will be generated with a jar file in it. Run this file in jar mode.

 java -jar ./target/demo-0.0.1-SNAPSHOT.jar
 
 so it runs.

 
8. Upload this jar to the server and write a sh or bat file to run independently.

 

 


Reference: https://www.cnblogs.com/ityouknow/p/5662753.html
Reference: https://www.cnblogs.com/chen110xi/p/6198483.html
Reference: https://www.cnblogs.com/ zs-notes/p/9359081.html
 

Guess you like

Origin blog.csdn.net/RoadToTheExpert/article/details/87790034