搭建springboot环境
?
?
1.前戲準備:
SpringBoot核心jar包:這里直接從Spring官網下載了1.5.9版本.
jdk:jdk1.8.0_45.
maven項目管理工具:3.5版本.
tomcat:8.5版本.
本地倉庫:注意settings.xml里面的設置"<localRepository>E:/SpringBoot/repository</localRepository>"紅色部分代表倉庫的位置.
eclipse:jee-neon3版本.
?
2.環境設置
1)將jdk以及maven的環境變量配置好,配好后在dos窗口進行測試:命令為java -version 和 mvn -v
JAVA_HOME:jdk所在目錄
path:%JAVA_HOME%\bin
clathpath:%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar
MAVEN_HOME:maven所在目錄
path:%MAVEN_HOME%\bin
?
2)eclipse設置
jre替換成1.8版本:Windows-->Preferences-->java-->Installed JREs
maven倉庫及路徑設置:Windows-->Preferences-->maven-->installations 新建一個maven
:Windows-->Preferences-->maven-->user settings 路徑都設為倉庫的settings.xml所在路徑
server:Windows-->Preferences-->server-->RunTime Environments 添加tomcat8.5
?
3.創建簡單的maven項目
創建一個maven start項目
pom.xml配置,紅色部分為重要部分
<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>
?
? <groupId>com.sinosoft</groupId>
? <artifactId>HelloSpring</artifactId>
? <version>0.0.1-SNAPSHOT</version>
? <packaging>jar</packaging>
?
? <name>HelloSpring</name>
? <url>http://maven.apache.org</url>
?
? <properties>
? ? <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
? </properties>
?
? <parent>
? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? <artifactId>spring-boot-starter-parent</artifactId>
? ? ? ? <version>1.5.9.RELEASE</version>
? </parent>
? <dependencies>
? ? <dependency>
? ? ? <groupId>junit</groupId>
? ? ? <artifactId>junit</artifactId>
? ? ? <version>3.8.1</version>
? ? ? <scope>test</scope>
? ? </dependency>
? ? <dependency>
? ? ? ? ?<groupId>org.springframework.boot</groupId>
? ? ? ? ?<artifactId>spring-boot-starter-web</artifactId>
? ? </dependency>
? </dependencies>
?</project>
?
? ?在src/main/java下新建一個Controller類
package com.sinosoft.HelloSpring;
? ?import java.io.IOException;
? ?import javax.servlet.http.HttpServletResponse;
? ?import org.springframework.boot.SpringApplication;
? ?import org.springframework.boot.autoconfigure.SpringBootApplication;
? ?import org.springframework.web.bind.annotation.RequestMapping;
? ?import org.springframework.web.bind.annotation.RestController;
?
? ?@RestController
? ?@SpringBootApplication
? ?public class HelloSpring {
@RequestMapping("/app")
void index(HttpServletResponse res) throws IOException{
res.getWriter().println("Hello World!");
}
?
public static void main(String[] args) {
SpringApplication.run(HelloSpring.class, args);
}
? }
運行main方法,在瀏覽器中輸入http://localhost:8080/app就能得到 Hello World! 的結果
?
4.瀏覽器差異可能導致的問題
最開始用的IE8瀏覽器,代碼及報錯如下:
@RestController
? ?@SpringBootApplication
? ?public class HelloSpring {
@RequestMapping("/app")
String index(){
? ?return "Hello World!";
}
?
public static void main(String[] args) {
SpringApplication.run(HelloSpring.class, args);
}
? }
可是我在360瀏覽器上卻可以正常運行并出結果,后來經查詢資料,得到這是ie8不支持
所以將紅色部分方法替換為
void index(HttpServletResponse res) throws IOException{
res.getWriter().println("Hello World!");
? ? }
便可在ie8上完美運行
?
這只是個開始...
?
轉載于:https://www.cnblogs.com/goujh/p/8394033.html
總結
以上是生活随笔為你收集整理的搭建springboot环境的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Day 9 函数的初识1
- 下一篇: jquery中的创建节点和添加节点的方法