springboot学习(一)
来源:互联网 发布:家具淘宝店名大全 编辑:程序博客网 时间:2024/05/29 03:14
公司最近要进行一个新的项目,之前因为比较懒,所以也没有了解过springboot。现在来个临时抱佛脚。并做下记录。
资料:
官网地址:http://projects.spring.io/spring-boot/
先参考官方文档来个Quick Start:
本人开发环境:apache-maven-3.5.0
eclipse-jee-luna-SR2-win32-x86_64
jdk1.8.0_131
采用maven方式构建项目:
1、在pom文件中添加依赖:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version></parent><dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency></dependencies>
问题:项目报错,需要maven==》update project报错:Java compiler level does not match the version of the installed Java project facet.
Dynamic Web Module 3.1 requires Java 1.7 or newer.
One or more constraints have not been satisfied.
原因:jdk默认版本是1.6,换成1.8即可。
官方建议:尽管你可以在Java6或Java7环境下使用Spring Boot,通常建议尽可能使用Java8。
这里采用maven插件的方式。
<build>
<plugins>
<!-- jdk版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
<compilerArguments>
<verbose />
<bootclasspath>${java.home}/lib/rt.jar;${java.home}/lib/jce.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
更正:通过上面的方法可以达到目的,但是好像直接添加
2.启动类。
package hello;import org.springframework.boot.*;import org.springframework.boot.autoconfigure.*;import org.springframework.stereotype.*;import org.springframework.web.bind.annotation.*;//@RestController @RestController注解相当于@ResponseBody+@Controller合在一起@Controller@EnableAutoConfigurationpublic class SampleController { @RequestMapping("/") @ResponseBody String home() { return "Hello World!"; } public static void main(String[] args) throws Exception { SpringApplication.run(SampleController.class, args); }}
OK。按照官方的Quick Start springboot的入门就这样了。现在直接用main启动。ulr:http://localhost:8080/就可以访问到了。@EnableAutoConfiguration ,这个注解告诉Spring Boot根据添加的jar依赖猜测你想如何配置Spring。由于 spring-boot-starter-web 添加了Tomcat和Spring MVC,所以auto-configuration将假定你正在开发一个web应用,并对Spring进行相应地设置。
至此结束,不足之处欢迎指出。Thanks。。。。
- springBoot 学习(一)
- springboot学习(一)
- SpringBoot学习(一)
- SpringBoot学习(一)SpringBoot基础入门
- SpringBoot学习(一)入门
- springboot 学习笔记(一)
- springboot 学习笔记(一)
- springBoot 学习记录(一)
- springboot 学习笔记(一)
- springboot学习总结(一)
- SpringBoot学习总结(一)
- SpringBoot学习(一)--构建第一个SpringBoot工程
- springboot学习笔记(一)
- SpringBoot学习篇一
- SpringBoot学习笔记(一)
- SpringBoot学习一
- SpringBoot学习(一)
- SpringBoot学习笔记一
- flowable IdmEngine和IdmEngineConfiguration
- Codeforces Round #426 (Div. 2)
- struts2-文件上传
- 一分钟了解"matlab进行奇异值分解SVD"
- PHPStorm 添加支持 PSR-4 命名空间前缀设置
- springboot学习(一)
- Java1:迭代器模式
- 前端数据模板handlebars与jquery整合
- The Meaningless Game(思维题)
- table九宫格hover实现
- 使用IIS配置访问Cognos的WebService
- Java2:Java匿名内部类
- HDU 5135 Little Zu Chongzhi's Triangles(贪心)
- Codeforces Round #228 (Div. 1)A. Fox and Box Accumulation(逆向思维)