eclipse中创建spring-boot项目,打成可执行war包

1、创建maven项目
eclipse中创建spring-boot项目,打成可执行war包_第1张图片

eclipse中创建spring-boot项目,打成可执行war包_第2张图片

 

2、编辑pom文件
 




  4.0.0
	
    org.springframework.boot
    spring-boot-starter-parent
    1.5.10.RELEASE
	
  com.ayb
  srping-boot1
  0.0.1-SNAPSHOT
	war
  srping-boot1
  
  http://www.example.com

  
    UTF-8
    1.7
    1.7
  

  
    
      junit
      junit
      4.11
      test
    
    

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


        org.springframework.boot
        spring-boot-starter-tomcat
       
    
  

  
    
      
        
          maven-clean-plugin
          3.0.0
        
        
        
          maven-resources-plugin
          3.0.2
        
        
          maven-compiler-plugin
          3.7.0
        
        
          maven-surefire-plugin
          2.20.1
        
        
          maven-jar-plugin
          3.0.2
        
        
          maven-install-plugin
          2.5.2
        
        
          maven-deploy-plugin
          2.8.2
        
      
    
    
        
        
            org.springframework.boot
            spring-boot-maven-plugin
        
    

  

3、编辑启动类App.java

package foo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

/**
 * Hello world!
 *
 */
@SpringBootApplication
public class App extends SpringBootServletInitializer
{
	 @Override
	    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
	        return builder.sources(App.class);
	    }
    public static void main( String[] args )
    {
        SpringApplication.run(App.class,args);
        System.out.println("sss");
    }
}

4、创建Controller


eclipse中创建spring-boot项目,打成可执行war包_第3张图片

package foo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class OneController {
	@RequestMapping("/index")
	@ResponseBody
	public String index(){
		return "Hello World!";
	}
}

5、项目打包
eclipse中创建spring-boot项目,打成可执行war包_第4张图片

eclipse中创建spring-boot项目,打成可执行war包_第5张图片

6、部署到tomcat中,启动后修改项目名为spring-boot1
eclipse中创建spring-boot项目,打成可执行war包_第6张图片

7、关闭tomcat,重新启动,在浏览器访问该项目
eclipse中创建spring-boot项目,打成可执行war包_第7张图片

你可能感兴趣的:(eclipse)