Eclipse+Maven+Spring-boot快速構築

4615 ワード

最近も仕事の変換の原因でjavaが上手になり、springというものに触れ、さらに軽量級のspring-bootがあります.今日はspring-boot環境を簡単に構築し、簡単な応答を構築して戻ります.
eclipseを開くと、eclipseにmavenが統合されていることがわかります.ダウンロードする必要はありません.もしあなたのバージョンにない場合は、help->eclipseMarketPlaceでダウンロードしてインストールしてください.
次にfile->new->project->MavenProject->next->next->next->コンストラクションを選択(便利ならquickStarttを選びましょう)->next->GroupIdとArtifactIdを設定しますが、実は名前なので勝手に書きましょう.構築が完了すると、Mavenプロジェクトが生成されます.
次に、Pom.xmlに直接行って、対応する依存パッケージを設定します.具体的なxml:


  4.0.0
  com.monringstar
  myProject
  0.0.1-SNAPSHOT

  myProject
  http://maven.apache.org

  
    UTF-8
  

  
  	org.springframework.boot
  	spring-boot-starter-parent
  	1.4.1.RELEASE
  
       
            
            spring-snapshots    
            http://repo.spring.io/snapshot    
            true    
            
            
            spring-milestones    
            http://repo.spring.io/milestone    
            
        
        
            
            spring-snapshots    
            http://repo.spring.io/snapshot    
            
            
            spring-milestones    
            http://repo.spring.io/milestone    
            
    
  
    
    	  
	    org.springframework.boot  
	    spring-boot-starter-test  
	    test  
	  
	  
	    org.springframework.boot  
	    spring-boot-starter-web  
	  
	  
	    org.springframework.hateoas  
	    spring-hateoas  
	  
	  
	    org.springframework.boot  
	    spring-boot-starter-actuator  
	
    

が終わったら、まず右クリック工事Maven->updateで、何か間違いがあるかどうかを見て、この過程で対応する依存パッケージも工事にダウンロードします.
次に、Entity、Controller、および起動用のApplicationを追加してみます.
package com.monringstar.myEntity;

public class Entity {
	private String id;
	private String name;
	
	public String getId() {
		return id;
	}
	
	public String getName() {
		return name;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	public void setName(String name) {
		this.name = name;
	}
}
package com.monringstar.myProject;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
public class Application {


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


}package com.monringstar.myProject;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.monringstar.myEntity.Entity;

@RestController
@RequestMapping("/1")
public class myController {
	
	@RequestMapping("/{id}")
	public Entity view(@PathVariable("id") String id) {
		Entity entity = new Entity();
		entity.setId(id);
		entity.setName("  ");
		return entity;
	}
}
package com.monringstar.myProject;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

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

}

これで、内容を塗りつぶしただけで、次はbuild、右クリックエンジニアリング、run as->Maven build..対応するウィンドウにGoalsを設定します. clean package spring-boot:runついでに下のSkip Testsもチェックして、apply->runで結果が出て、運行が終わったら、ブラウザを開けてあなたの設定に対応するurlを入力します:例えば私のところはlocalhost:8080/1/(id)簡単に走って通じてからもっと多くのことをすることができます.