当前位置: 首页 > news >正文

中国空间站首次太空授课/苹果看国外新闻的app

中国空间站首次太空授课,苹果看国外新闻的app,连云港网站建设 连云港网站制作,注册网页代码2019独角兽企业重金招聘Python工程师标准>>> SpringBoot学习--HellWorld 相关代码: github OSCchina 引入pom依赖 1.spring-boot-starter-parent可以提供依赖管理,引入以后其它的的starter依赖就可以不用配置版本号.<parent><groupId>org.springframewo…

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

SpringBoot学习--HellWorld

相关代码: github OSCchina

引入pom依赖

  • 1.spring-boot-starter-parent可以提供依赖管理,引入以后其它的的starter依赖就可以不用配置版本号.
  <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.4.0.RELEASE</version></parent>

但是这里也有一个问题,如果我们已经有一个自己的parent,那么我们就不能在这么引用了.我们可以使用下面的方式:

 <dependencyManagement><dependencies><dependency><!-- Import dependency management from Spring Boot --><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>1.4.0.RELEASE</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
  • 2.spring-boot-starter-web提供了webmvc,tomcat等web开发相关模块
<dependencies>  <dependency>  <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-starter-web</artifactId>  </dependency>  </dependencies>  

开始HelloWorld

一个错误的示例

我们需要一个main作为入口来启动我们的项目,但这里我们需要注意我们启动的主类不能放在default包下, 不然会遇到很多莫名的问题,比如下面这个:

2017-03-26 20:06:27.320  WARN 8832 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [HelloWorldAppTest1]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'errorPageFilter' for bean class [org.springframework.boot.web.support.ErrorPageFilter] conflicts with existing, non-compatible bean definition of same name and class [org.springframework.boot.context.web.ErrorPageFilter]
2017-03-26 20:06:27.330 ERROR 8832 --- [           main] o.s.boot.SpringApplication               : Application startup failedorg.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [HelloWorldAppTest1]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'errorPageFilter' for bean class [org.springframework.boot.web.support.ErrorPageFilter] conflicts with existing, non-compatible bean definition of same name and class [org.springframework.boot.context.web.ErrorPageFilter]

编写我们的第一个HelloWorld

@SpringBootApplication
@RestController
public class HelloWorldApp2 {@RequestMapping("/hello")public String hello() {return "hello world";}@RequestMapping("/")public String index() {return "this is index page";}/*** 用于启动项目** @param args*/public static void main(String[] args) {SpringApplication.run(HelloWorldApp2.class, args);}}

启动项目

我们只需要启动main方法就可以在浏览器访问localhost:8080/hello,当然我们也可以使用maven命令来启动,我们需要添加下面的插件

   <build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build>

然后使用mvn spring-boot:run就可以启动项目了,除此之外,我们也可以使用jar包的方式来启动,

java -jar target/SpringBoot-HelloWorld-2-1.0-SNAPSHOT.jar 

相关注解

  • 1.@SpringBootApplication可以自动进行一些必要的默认配置,等价于@Configuration,@EnableAutoConfiguration和@ComponentScan 这三个注解.
  • 2.RestController我们可以直接返回json,当然,从名字我们也知道可以直接用来编写RESTTUL风格的接口,要注意的是这个注解相当于一个@ResponseBody 注解,我们只能返回json,不能返回View了.

转载于:https://my.oschina.net/lengchuan/blog/876394

http://www.jmfq.cn/news/5073931.html

相关文章:

  • 网络营销企业网站优化/爱站网域名查询
  • 手机企业网站源码/上海小红书seo
  • 菏泽 兼职做网站/建立网站的基本步骤
  • 编程序可以做网站吗/google search
  • 在线购物网站建设/东莞seo快速排名
  • 我想找个做代理的网站/百度提交入口地址在哪
  • 大理建设学校官方网站/南宁网络推广培训机构
  • 西安大网站建设公司排名/seo知识是什么意思
  • 网站开发概述/大数据营销系统怎么样
  • 阿里服务器可以做多少个网站/网络seo营销推广
  • 2021给个手机直接能看的/郑州网站seo服务
  • 建设一个公司网站要具备什么/近期国内新闻摘抄
  • 衢州哪里有做网站的公司4000-262-/重庆百度推广开户
  • 重庆做网站建设的公司/站长网站大全
  • 网站怎样做谷歌推广/赣州seo顾问
  • 寺院网站建设/百度推广官网
  • 手机网站建站cms/最新中高风险地区名单
  • 南山网站建设公司/网店怎么开
  • 网站关键词没被搜出来/专业网站seo推广
  • 网站建设就问山东聚搜网络f/酒店网络营销方式有哪些
  • vue做的个人网站/百度竞价推广课程
  • dede生成网站地图/成都疫情最新情况
  • 龙口做网站价格/做网站的外包公司
  • 厦门网站推广步骤机构/代发关键词包收录
  • 能源公司网站建设/如何进行市场推广
  • 电脑做系统网站/网页开发需要学什么
  • 网站定制开发要多久/线上广告投放渠道
  • 做网站霸屏公司销售好做吗/申请域名的方法和流程
  • 杭州模板网站建站/互联网广告推广公司
  • 合肥专门做网站的公司/网络推广优化品牌公司