java-springboot-tomcat 搭建
一、优点
1.搭建一个 spring mvc 项目只需要1分钟
2.不用配置 web.xml 和 各种xml
3.多种方式启动项目
3.1 开发阶段使用 mvn 命令运行
3.2 打成 war 包后,使用 java -jar 命令运行
3.3 打成 war 包后,部署到 tomcat 运行
二、资料
官网:http://projects.spring.io/spring-boot/
三、搭建第一个 springboot 项目
1.环境
ide:idea
jdk:1.7
springboot:1.5.6
2.创建 idea module,命名为 SbootDemo2
2.1 file=>new=>mudule...
2.2 选择 Spring Initializr:module sdk 选择 1.7,其他默认。下一步
2.3 填写一些包信息,packaging 选择 war,java version 选择 1.7;下一步
2.4 找到 web 节点,勾选 web 复选框,生成一个 web 项目;(这步很关键,可以生成一个 ServletInitializer 类);下一步
2.5 选择生成路径,点击 finish,完成一个 springboot 项目创建;
3.项目也可使用 spring 提供的在线生成工具,在线生成
地址:https://start.spring.io/
4.打开项目将看到有两个类
SbootDemo2Application.java //springboot 主项目,应用程序入口
ServletInitializer.java //tomcat 启动入口
5.新建一个 mvc 的 controller
package com.example.demo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
@RestController
public class HeloController {
@RequestMapping("/")
public String hello(){
System.err.println("HeloController.hello();");
return "hello demo2 ..."+ new Date();
}
}
6.运行项目
6.1 mvn 命令运行
1>使用 cd 命令定位到项目根目录
2>输入 mvn spring-boot:run 命令
3>看到以下内容表示运行成功了
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.6.RELEASE)
4>打开浏览器输入:http://local:8080/ 查看运行结果
5>springboot 默认使用 8080 端口,改变端口需要配置 application.properties 文件
6.2 使用 java -jar 命令,运行项目
1> 使用 cd 命令定位到项目根目录
2> 将项目打成 war 包; 命令:mvn clean package -Dmaven.test.skip=true
3> 复制已经打完的 war 包完整路径,执行以下命令运行
java -jar /sboot-demo2/target/sboot-demo2-0.0.1-SNAPSHOT.war
4>看到以下内容表示运行成功了
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.6.RELEASE)
5>打开浏览器输入:http://local:8080/ 查看运行结果
6>springboot 默认使用 8080 端口,改变端口需要配置 application.properties 文件
6.3 部署到 tomcat 运行
1>将打成的 war 包,复制到 tomcat webapps 目录,运行 bin 目录中的 startup.sh
6.4 配置开发环境中的 tomcat ,也可以使用 开发工具 运行
一、优点
1.搭建一个 spring mvc 项目只需要1分钟
2.不用配置 web.xml 和 各种xml
3.多种方式启动项目
3.1 开发阶段使用 mvn 命令运行
3.2 打成 war 包后,使用 java -jar 命令运行
3.3 打成 war 包后,部署到 tomcat 运行
二、资料
官网:http://projects.spring.io/spring-boot/
三、搭建第一个 springboot 项目
1.环境
ide:idea
jdk:1.7
springboot:1.5.6
2.创建 idea module,命名为 SbootDemo2
2.1 file=>new=>mudule...
2.2 选择 Spring Initializr:module sdk 选择 1.7,其他默认。下一步
2.3 填写一些包信息,packaging 选择 war,java version 选择 1.7;下一步
2.4 找到 web 节点,勾选 web 复选框,生成一个 web 项目;(这步很关键,可以生成一个 ServletInitializer 类);下一步
2.5 选择生成路径,点击 finish,完成一个 springboot 项目创建;
3.项目也可使用 spring 提供的在线生成工具,在线生成
地址:https://start.spring.io/
4.打开项目将看到有两个类
SbootDemo2Application.java //springboot 主项目,应用程序入口
ServletInitializer.java //tomcat 启动入口
5.新建一个 mvc 的 controller
package com.example.demo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
@RestController
public class HeloController {
@RequestMapping("/")
public String hello(){
System.err.println("HeloController.hello();");
return "hello demo2 ..."+ new Date();
}
}
6.运行项目
6.1 mvn 命令运行
1>使用 cd 命令定位到项目根目录
2>输入 mvn spring-boot:run 命令
3>看到以下内容表示运行成功了
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.6.RELEASE)
4>打开浏览器输入:http://local:8080/ 查看运行结果
5>springboot 默认使用 8080 端口,改变端口需要配置 application.properties 文件
6.2 使用 java -jar 命令,运行项目
1> 使用 cd 命令定位到项目根目录
2> 将项目打成 war 包; 命令:mvn clean package -Dmaven.test.skip=true
3> 复制已经打完的 war 包完整路径,执行以下命令运行
java -jar /sboot-demo2/target/sboot-demo2-0.0.1-SNAPSHOT.war
4>看到以下内容表示运行成功了
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.6.RELEASE)
5>打开浏览器输入:http://local:8080/ 查看运行结果
6>springboot 默认使用 8080 端口,改变端口需要配置 application.properties 文件
6.3 部署到 tomcat 运行
1>将打成的 war 包,复制到 tomcat webapps 目录,运行 bin 目录中的 startup.sh
6.4 配置开发环境中的 tomcat ,也可以使用 开发工具 运行