spring boot----第一天(初识,搬运官网内容)

来源:互联网 发布:金山翻译软件 编辑:程序博客网 时间:2024/06/06 00:33

今天第一天正式开始学习spring boot,以下根据官网Building an Application with Spring Boot进行的学习

1、项目采用maven进行构建,相应的pom.xml如下:

  <build>    <finalName>springmvc</finalName>    <plugins>      <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-compiler-plugin</artifactId>        <configuration>          <source>1.8</source>          <target>1.8</target>        </configuration>      </plugin>    </plugins>  </build>    <parent>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-parent</artifactId>        <version>1.5.5.RELEASE</version>    </parent>  <dependencies>      <dependency>          <groupId>org.springframework.boot</groupId>          <artifactId>spring-boot-starter-web</artifactId>      </dependency>    <dependency>      <groupId>org.springframework.boot</groupId>      <artifactId>spring-boot-starter-test</artifactId>      <scope>test</scope>    </dependency>  </dependencies>
今天在单元测试的时候,出现运行一直报错的情况,原因到最后查明是springboot版本跟spring版本jar包不兼容造成的,所以建议不要在pom.xml单独写spring的依赖,就只写springboot的,spring的自己就会自动加载,以免出现兼容问题。

2、编写HelloController

package com.jie.controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class HelloController{    @RequestMapping("/")    public String index(){        return "hello spring boot";    }}

3、编写客户端类

package com.jie;import org.springframework.boot.CommandLineRunner;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.context.ApplicationContext;import org.springframework.context.annotation.Bean;import java.util.Arrays;@SpringBootApplicationpublic class Application{    public static void main(String[] args) {        SpringApplication.run(Application.class,args);    }    @Bean    public CommandLineRunner commandLineRunner(ApplicationContext ctx){        return args -> {            System.out.println("let's inspect the  beans provided by Spring Boot:");            String [] beanNames = ctx.getBeanDefinitionNames();            Arrays.sort(beanNames);            for (String beanName : beanNames) {                System.out.println(beanName);            }        };    }}

4.运行以上

let's inspect the  beans provided by Spring Boot:applicationbasicErrorControllerbeanNameHandlerMappingbeanNameViewResolvercharacterEncodingFiltercommandLineRunnerconventionErrorViewResolverdefaultServletHandlerMappingdefaultValidatordefaultViewResolverdispatcherServletdispatcherServletRegistrationduplicateServerPropertiesDetectorembeddedServletContainerCustomizerBeanPostProcessorerrorerrorAttributeserrorPageCustomizererrorPageRegistrarBeanPostProcessorfaviconHandlerMappingfaviconRequestHandlerhandlerExceptionResolverhelloControllerhiddenHttpMethodFilterhttpPutFormContentFilterhttpRequestHandlerAdapterjacksonObjectMapperjacksonObjectMapperBuilderjsonComponentModulelocaleCharsetMappingsCustomizermappingJackson2HttpMessageConvertermbeanExportermbeanServermessageConvertersmethodValidationPostProcessormultipartConfigElementmultipartResolvermvcContentNegotiationManagermvcConversionServicemvcPathMatchermvcResourceUrlProvidermvcUriComponentsContributormvcUrlPathHelpermvcValidatormvcViewResolver

程序不抛异常,出现类似的这一段就说明运行成功
5、谢了这一会儿发现还是官网清楚,唉,写写屡屡思路吧

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 孕晚期血糖高怎么办啊 被过山风咬了怎么办 大腿上长肥胖纹怎么办 减肥减的胸小了怎么办 手机刷机变砖了怎么办 手部肌肉萎缩了怎么办 龙吐珠花冻着了怎么办 发财树浇水多了怎么办 发财树根部烂了怎么办 发财树的根烂了怎么办 淘米水发酵臭了怎么办 眼睛下的小细纹怎么办 内眼角开的太小怎么办 做完美瞳眼睛红怎么办 纹完眼线眼睛红怎么办 21岁眼下小细纹怎么办 20岁眼部有细纹怎么办 纹身几天后晕色怎么办 屁眼长了痔疮大怎么办 苹果os系统坏了怎么办 苹果6出现白苹果怎么办 苹果平板白屏了怎么办 腿上的皮肤很干怎么办 鱼身上掉了鳞片怎么办 患上恋爱恐慌症怎么办 我觉得活着好累怎么办 我的世界遇到him怎么办 孕妇闻了樟脑球怎么办 电脑不能识别u盘怎么办 电脑识别不了u盘怎么办 神之子武器爆了怎么办 中控本考试没过怎么办 震后安全逃生后怎么办 逃出电梯游戏2关怎么办 车尾灯灯罩破了怎么办 着火了吸入了烟怎么办 多媒课件着火了怎么办 用手楚了眼睛疼怎么办 眼睛又痒又干涩怎么办 比熊吃了奥利奥怎么办 怪物猎人x迷路了怎么办