eclipse 搭建spring boot框架

一.建立maven工程

①File——New——Other

eclipse 搭建spring boot框架_第1张图片

②选择Maven Project后,点击Next

eclipse 搭建spring boot框架_第2张图片

eclipse 搭建spring boot框架_第3张图片

④.输入Group Id、Artifact Id

eclipse 搭建spring boot框架_第4张图片

⑤.点击Finish后,建立工程如下:

eclipse 搭建spring boot框架_第5张图片

 

二、配置工程:

①.鼠标右键点击工程目录,新增Package,起名为resources (这个文件夹放配置文件用 ,其实不用这个spring boot也能启动)

eclipse 搭建spring boot框架_第6张图片

②.在resources文件夹下,增加文件application.properties,内容如下

eclipse 搭建spring boot框架_第7张图片

server.port是启动的端口。

同样建立conf目录

把resouces和conf目录加到资源目录中

eclipse 搭建spring boot框架_第8张图片

 

eclipse 搭建spring boot框架_第9张图片

 

eclipse 搭建spring boot框架_第10张图片

③.更改pom.xml文件

    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4.0.0
    com.demo.springboot
    spring-boot
    0.0.1-SNAPSHOT


    
        org.springframework.boot
        spring-boot-starter-parent
        1.5.9.RELEASE
    

    
        
            org.springframework.boot
            spring-boot-starter
        

        
            org.springframework.boot
            spring-boot-starter-web
        

    

    
    
        
            
                resources
                
                
                    application.properties
                

                
                
                    *.xml
                    *.yaml
                

            

        

        
            
                org.springframework.boot
                spring-boot-maven-plugin
            

            
            
                maven-resources-plugin
                
                    
                        copy-resources
                        validate
                        
                            copy-resources
                        

                        
                            
                            ${project.build.directory}/conf
                            
                                
                                
                                    conf
                                    true
                                

                            

                        

                    
                
            
        
    

 

④.右键点工程Maven——Update Project

eclipse 搭建spring boot框架_第11张图片

⑤.新建Application.java作为main入口,@RequestMapping("/")作http访问用根目录地址

 

eclipse 搭建spring boot框架_第12张图片

package com.neusoft;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
@EnableAutoConfiguration
@ComponentScan
public class Application implements EmbeddedServletContainerCustomizer{
//implements EmbeddedServletContainerCustomizer
    

    public static void main(String[] args) {
        // http://localhost:8080/
        SpringApplication.run(Application.class, args);
    }

    public void customize(ConfigurableEmbeddedServletContainer arg0) {
        //arg0.setPort(8081);
        
    }
    
    @RequestMapping("/")
    public String hello(){
        return "Greetings from Spring Boot!";
    }
    
    @RequestMapping("/first.do")
    String home() {
        return "Hello World!";
    }
}
 

保存后,运行

eclipse 搭建spring boot框架_第13张图片

打开浏览器,访问

eclipse 搭建spring boot框架_第14张图片

你可能感兴趣的:(java)