spring boot教程(1) -- hello springbooot

  1. 目的:

     搭建一个spring boot框架的项目环境 能进行网页访问
    
  2. 使用工具:

      eclipse + maven + tomcat7.0.67
    
  3. 程序结构
    这里写图片描述

  4. 使用maven的pom.xml导jar包:


<dependencies>
  	<dependency>
	  <groupId>org.springframework.boot</groupId>
	  <artifactId>spring-boot-starter</artifactId>
	  <version>1.3.2.RELEASE</version>
	</dependency>
	<dependency>
	  <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-test</artifactId>
	  <version>1.3.2.RELEASE</version>
	</dependency>
	<dependency>
	  <groupId>org.springframework.boot</groupId>
	  <artifactId>spring-boot-starter-web</artifactId>
	 <version>1.3.2.RELEASE</version>
	   <!--  1.修改pom,排除内嵌tomcat8插件 -->
1.  <exclusions>
		 <exclusion>               <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions> 
	</dependency>
2. <dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-juli</artifactId>
    <version>7.0.67</version>
</dependency>
  </dependencies>

  1. 写一个@SpringBootApplication // 是用来初始化配置文件 在以后可以自行配置

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

@SpringBootApplication
public class ApplicationSpring {
	public static void main(String[] args) {
		// 启动配置 自动扫描注解
		SpringApplication.run(ApplicationSpring.class, args);  
	}
}

  1. 写一个带注解HelloSpring类 映射路径

package cn.springboot;

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

@RestController
public class HelloSpring {
	@RequestMapping("/hello")
	public String index(ModelMap map) {
		map.addAttribute("host", "http://blog.csdn.net/qq_33399709");
		return "index";
	}
}

  1. 编写index.html模版文件

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8" />
    <title></title>
</head>
<body>
<!-- 如果host中有值 就显示host中存储的值,否则显示hello world -->
<h1 th:text="${host}">Hello World</h1>
</body>
</html>
  1. 启动 ApplicationSpring 类

使用http://localhost:8080/hello 就可以成功访问 (这里不需要添加项目名)

这里写图片描述

  1. 总结问题

  1. spring boot 内嵌Tomcat8 如果Tomcat不匹配 就需要将内嵌的Tomcat8给注释掉
    使用在pom.xml 引入jar

  2. 8080端口被占用的情况
    1). 使用cmd命令 输入 netstat -aon|findstr “8080” 查看出PID号 然后打开任务管理器 -->服务 找到对应的PID将任务关闭
    Java技术干货

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Java技术干货

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值