搭建springboot项目
1.搭建环境windows10+jdk1.8+eclipse4.8+maven
2.为了学习微服务架构学习搭建基础项目
3.分为两种搭建方式为maven项目和单独建立springboot项目(eclipse需要安装相关的插件)
第一种使用maven搭建
1)创建maven项目 file--new---other --maven-project
2) 配置pom文件将springbootz相关的包引入
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelversion>4.0.0</modelversion>
<!-- spring boot基本环境 -->
<parent>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-parent</artifactid>
<version>1.5.6.release</version>
</parent>
<groupid>com.wj</groupid>
<artifactid>springboot</artifactid>
<version>0.0.1-snapshot</version>
<name>springboot</name>
<!-- fixme change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceencoding>utf-8</project.build.sourceencoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupid>junit</groupid>
<artifactid>junit</artifactid>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!--web应用基本环境配置 -->
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-web</artifactid>
</dependency>
</dependencies>
<build>
<pluginmanagement><!-- lock down plugins versions to avoid using maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactid>maven-clean-plugin</artifactid>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#plugin_bindings_for_jar_packaging -->
<plugin>
<artifactid>maven-resources-plugin</artifactid>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactid>maven-compiler-plugin</artifactid>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactid>maven-surefire-plugin</artifactid>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactid>maven-jar-plugin</artifactid>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactid>maven-install-plugin</artifactid>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactid>maven-deploy-plugin</artifactid>
<version>2.8.2</version>
</plugin>
<!-- spring-boot-maven-plugin插件就是打包spring boot应用的 -->
<plugin>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-maven-plugin</artifactid>
</plugin>
</plugins>
</pluginmanagement>
</build>
</project>
3)创建先关的资源文件包 src/main/java 和src/main/resources
4) 创建测试的类
新建目录com.springboot和com.spring.web两个目录
在com.wj.spring目录下新建类app.java
package com.wj.springboot;
import org.springframework.boot.springapplication;
import org.springframework.boot.autoconfigure.springbootapplication;
/**
* hello world!
*
*/
@springbootapplication
public class app {
public static void main(string[] args) {
springapplication.run(app.class, args);
}
}
在com.wj.spring.web下新建类onecontroller.java
package com.wj.springboot.web;
import org.springframework.stereotype.controller;
import org.springframework.web.bind.annotation.requestmapping;
import org.springframework.web.bind.annotation.responsebody;
@controller
public class onecontroller {
@requestmapping("/")
@responsebody
public string index() {
return "hello spring boot";
}
}
5)然后run运行app.java启动项目,看日志输出窗口出现下图
6)在浏览器打开路径http://localhost:8080出现下边的图例
即搭建成功
第二种通过新建springboot项目创建
1)eclipse安装springboot相关插件
首先查看eclispe的版本
然后安装springboot相关插件spring-tool-suite
eclipse --> help--> install new sofware
2)创建项目
3)run运行springbootsapplication.java
4)浏览器 访问http://localhost:8080