这里我们记录一下springboot的使用,第一次创建环境。

springboot的使用

项目结构如下:

一、我们使用maven去构建springboot的依赖。其中我们使用的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.linux.huhx</groupId>
<artifactId>SpringBootTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.1.RELEASE</version>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

build里面是使用jre1.7去构建项目,我下载的maven默认是用1.5。依赖下载的jar包如下。

spring-boot-starter-web-1.5.1.RELEASE.jar
spring-boot-starter-1.5.1.RELEASE.jar
spring-boot-1.5.1.RELEASE.jar
spring-boot-autoconfigure-1.5.1.RELEASE.jar
spring-boot-starter-logging-1.5.1.RELEASE.jar
logback-classic-1.1.9.jar
logback-core-1.1.9.jar
slf4j-api-1.7.22.jar
jcl-over-slf4j-1.7.22.jar
jul-to-slf4j-1.7.22.jar
log4j-over-slf4j-1.7.22.jar
spring-core-4.3.6.RELEASE.jar
snakeyaml-1.17.jar
spring-boot-starter-tomcat-1.5.1.RELEASE.jar
tomcat-embed-core-8.5.11.jar
tomcat-embed-el-8.5.11.jar
tomcat-embed-websocket-8.5.11.jar
hibernate-validator-5.3.4.Final.jar
validation-api-1.1.0.Final.jar
jboss-logging-3.3.0.Final.jar
classmate-1.3.1.jar
jackson-databind-2.8.6.jar
jackson-annotations-2.8.0.jar
jackson-core-2.8.6.jar
spring-web-4.3.6.RELEASE.jar
spring-aop-4.3.6.RELEASE.jar
spring-beans-4.3.6.RELEASE.jar
spring-context-4.3.6.RELEASE.jar
spring-webmvc-4.3.6.RELEASE.jar
spring-expression-4.3.6.RELEASE.jar

二、SimpleController.java的代码如下:

package com.linux.huhx;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; @Controller
@EnableAutoConfiguration
public class SimpleController {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
@ResponseBody
public String hello() {
return "hello world";
} public static void main(String[] args) {
SpringApplication.run(SimpleController.class, args);
}
}

三、右击run,运行SimpleController的java项目。会有大致以下的输出日志。

  .   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.1.RELEASE) 2017-02-24 17:43:31.997 INFO 19476 --- [ main] com.linux.huhx.SimpleController : Starting SimpleController on Linux with PID 19476 (G:\Java\JavaEE\Program\2016-11-18\SpringBootTest\target\classes started by huhx in G:\Java\JavaEE\Program\2016-11-18\SpringBootTest)
2017-02-24 17:43:32.003 INFO 19476 --- [ main] com.linux.huhx.SimpleController : No active profile set, falling back to default profiles: default
2017-02-24 17:43:32.064 INFO 19476 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@293f78d3: startup date [Fri Feb 24 17:43:32 CST 2017]; root of context hierarchy
2017-02-24 17:43:33.331 INFO 19476 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration' of type [class org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-02-24 17:43:33.408 INFO 19476 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'validator' of type [class org.springframework.validation.beanvalidation.LocalValidatorFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-02-24 17:43:33.942 INFO 19476 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-02-24 17:43:33.953 INFO 19476 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2017-02-24 17:43:33.954 INFO 19476 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.11
2017-02-24 17:43:34.047 INFO 19476 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-02-24 17:43:34.048 INFO 19476 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1987 ms
2017-02-24 17:43:34.219 INFO 19476 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-02-24 17:43:34.223 INFO 19476 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-02-24 17:43:34.224 INFO 19476 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-02-24 17:43:34.224 INFO 19476 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-02-24 17:43:34.225 INFO 19476 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-02-24 17:43:34.545 INFO 19476 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@293f78d3: startup date [Fri Feb 24 17:43:32 CST 2017]; root of context hierarchy
2017-02-24 17:43:34.668 INFO 19476 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello],methods=[GET]}" onto public java.lang.String com.linux.huhx.SimpleController.hello()
2017-02-24 17:43:34.674 INFO 19476 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-02-24 17:43:34.674 INFO 19476 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-02-24 17:43:34.721 INFO 19476 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-02-24 17:43:34.721 INFO 19476 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-02-24 17:43:34.784 INFO 19476 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-02-24 17:43:35.042 INFO 19476 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-02-24 17:43:35.100 INFO 19476 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-02-24 17:43:35.105 INFO 19476 --- [ main] com.linux.huhx.SimpleController : Started SimpleController in 3.557 seconds (JVM running for 4.123)

四、在浏览器中输入: http://localhost:8080/hello。在页面会显示hello world字样。截图如下:

注意url不是:http://localhost:8080/SpringBootTest/hello

从中遇到的问题

一、启动时报错:Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

解决方案:在SimpleController类上面,需要加上@EnableAutoConfiguration注解。

二、输入url运行:Whitelabel Error Page  This application has no explicit mapping for /error, so you are seeing this as a fallback.

解决方案:在SimpleController类上面,需要加上@Controller注解。

友情链接

springboot的使用: http://www.cnblogs.com/God-/p/5857428.html

springboot---->springboot的使用(一)的更多相关文章

  1. (入门SpringBoot)SpringBoot发送邮件(十一)

    SpringBoot配置邮件服务: 1.引入jar <!-- 邮件 --> <dependency>    <groupId>org.springframework ...

  2. (入门SpringBoot)SpringBoot结合定时任务task(十)

    SpringBoot整合定时任务task 使用注解EnableScheduling在启动类上. 定义@Component作为组件被容器扫描. 表达式生成地址:http://cron.qqe2.com ...

  3. (入门SpringBoot)SpringBoot后台验证(八)

    后台验证的作用主要是防止postman...等等工具的恶意提交,前后台都判断数据,双保险. .可以在SpringBoot传参数 加上NotNull.... //分组Default,分组的好处就是可重复 ...

  4. (入门SpringBoot)SpringBoot结合拦截器(七)

    SpringBoot拦截器: 拦截器还是照旧和springmvc一样: @Componentpublic class MyInterceptor implements HandlerIntercept ...

  5. (入门SpringBoot)SpringBoot结合logback(六)

    SpringBoot结合logback日志: 1.配置资源文件: #日志配置信息logbacklogging.config=classpath:logback-spring.xmllog.path=E ...

  6. (入门SpringBoot)SpringBoot结合redis(四)

    SpringBoot整合redis: 1.引入jar <!--  引入redis依赖 --><dependency>    <groupId>org.springf ...

  7. SpringBoot | SpringBoot启动错误

    Error starting ApplicationContext. To display the conditions report re-run your application with 'de ...

  8. (入门SpringBoot)SpringBoot项目数据源以及整合mybatis(二)

    1.配置tomcat数据源: #   数据源基本配置spring.datasource.url=jdbc:mysql://localhost:3306/shoptest?useUnicode=true ...

  9. (入门SpringBoot)SpringBoot来临(一)

    .创建独立的Spring应用程序. .嵌入tomcat,Jetty或者Undertow,无需部署war文件; .允许通过Maven来获取starter; .尽可能的自动配置Spring. .提供生产就 ...

  10. (入门SpringBoot)SpringBoot加接口操作日志好方法(九)

    用Spring的切面去做,慕课网上的大神的小妙招,被我拷贝下来了.import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotati ...

随机推荐

  1. git学习(三):git暂存区

    回顾之前学过的命令: git init // 初始化一个项目 git add // 将文件交给工作区 git commit // 提交修改 查看提交日志: git log // 查看提交日志 git ...

  2. 配置TOMCAT 修改默认ROOT路径

    本文转载http://xxs673076773.iteye.com/blog/1134805 最合适的) 最直接的办法是,删掉tomcat下原有Root文件夹,将自己的项目更名为Root. 我在$to ...

  3. BloomFilter——大规模数据处理利器[转]

    原文链接:原文 Bloom Filter是由Bloom在1970年提出的一种多哈希函数映射的快速查找算法.通常应用在一些需要快速判断某个元素是否属于集合,但是并不严格要求100%正确的场合. 一. 实 ...

  4. salt '*' state.highstate 报错找不到文件,环境如下No Top file or master_tops data matches found.

    salt '*' state.highstate 报错找不到文件,环境如下No Top file or master_tops data matches found. file_roots:    b ...

  5. Connector/c++ 查询Mysql,出现 can't fetch because not on result set 错误

    使用 Connector/C++ 查询 Mysql 时,出现错误,提示如下: can't fetch because not on result set, 出现原因可以看这里:http://stack ...

  6. Ubuntu-Python2.7安装 scipy,numpy,matplotlib 和pip

    一. scipy,numpy,matplotlib sudo apt-get install python-scipy sudo apt-get install python-numpy sudo a ...

  7. thinkphp 第一个设计总结

    1.thinkphp的无限级分类不是万能的... 2.感觉先看前台(根据前台设计数据库)后写控制代码(后台),速度或许会快一点,思路明确...

  8. 关于Cocos2d-x中节点的获取

    方法一: 1.在.h文件的属性里面先声明要使用的节点或者变量. private: Label *scorelabel; 2.在.cpp文件中创建并使用这个节点或者变量. scorelabel = La ...

  9. 机器学习理论之SVM

    支持向量机系列 (1) 算法理论理解 http://blog.pluskid.org/?page_id=683 手把手教你实现SVM算法(一) (2) 算法应用 算法应用----python 实现实例 ...

  10. Python下opencv使用笔记(十)(图像频域滤波与傅里叶变换)

    前面以前介绍过空间域滤波,空间域滤波就是用各种模板直接与图像进行卷积运算,实现对图像的处理,这个方案直接对图像空间操作,操作简单.所以也是空间域滤波. 频域滤波说究竟终于可能是和空间域滤波实现相同的功 ...