Spring Boot学习---1.快速构建mvc模式项目
来源:互联网 发布:网络调试助手cm精装版 编辑:程序博客网 时间:2024/05/16 09:26
Spring越来越强大了,因工作中都开始使用spring boot快速搭建项目,且去除xml配置,发觉使用springBoot后项目开发非常迅速,工作之余想自己从头了解整个springBoot,因此记下学习记录
一、引入springBoot
对应在pom文件中加入如下代码:
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.1.RELEASE</version> </parent>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId> </dependency>
只需要加上以上代码,在parent中引入parent的version,在依赖中不需要指定对应web的version,springBoot会自动匹配对应需要的依赖包和版本,完成以上引入后就可以写代码了~
二、写controller类
如下:
import org.springframework.boot.*;import org.springframework.boot.autoconfigure.*;import org.springframework.stereotype.*;import org.springframework.web.bind.annotation.*;@RestController@EnableAutoConfigurationpublic class Example { @RequestMapping("/test") String home() { return "Hello World!"; } public static void main(String[] args) throws Exception { SpringApplication.run(Example.class, args); }}写完代码后,就可以直接运行man方法也就是eclipse中的 run as -- java application,此时spring-boot会使用内置依赖的tomcat启动程序,默认端口是8080,启动成功然后在浏览器中访问 http://localhost:8080/test 就能看到 “hello world” 了
三、注意
在启动中第一次启动会有以下报错信息:
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactoryat org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]at test.api.controller.Application.main(Application.java:22) [classes/:na]
出现这个错误的原因是缺少tomcat-juli.jar包,需要在pom文件中引入,解决办法如下:
<dependency><groupId>org.apache.tomcat</groupId><artifactId>tomcat-juli</artifactId></dependency>
0 0
- Spring Boot学习---1.快速构建mvc模式项目
- 快速构建Spring Boot项目
- spring boot项目快速构建(spring mvc+jpa+hibernate+mysql+gradle)
- Maven简单、快速构建spring mvc项目
- 采用Gradle快速构建基于Spring boot的MVC应用
- 使用spring boot快速构建spring框架的maven项目
- 使用 Spring Boot 快速构建 Spring 框架应用---学习笔记
- Maven快速使用教程(二) spring boot 项目构建
- 快速构建Spring Boot 1.5.8 maven Web 项目
- Spring Boot系列一----使用idea快速构建Spring boot项目
- ant构建spring boot 项目
- 关于spring boot - 快速构建spring程序
- Maven构建一个最简单的Spring Boot + Spring MVC项目
- Maven构建一个多模块的Spring Boot + Spring MVC项目,完全基于java config
- Spring MVC快速入门-Spring boot
- 快速搭建Spring Boot+Spring MVC
- 快速搭建Spring Boot项目
- Spring Boot 项目快速搭建
- solr5.5+tomcate7部署
- MxNet系列——get_started——amazonlinux_setup
- 蟠桃记
- web textarea
- Opengl函数(2)
- Spring Boot学习---1.快速构建mvc模式项目
- Pinterest日均1000+次试验的A/B测试平台揭秘
- 数据库隔离级别
- 【Python】实现网站备份文件扫描+源码分析
- MxNet系列——get_started——setup
- LeetCode9. Palindrome Number(Python)兼翻译
- 使用json_decode()的一些小积累
- MaltReport2:基于 OpenDocument-OpenOfficeXML 的开源报表引擎
- RedHat6.4安装Elasitcsearch5.2.0