热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

SpringBoot第一个示例

start.spring.io导出示例,竟然发现妹的跑不起来。参考过逃离沙漠的博客,添加了org.sprin

start.spring.io导出示例,竟然发现妹的跑不起来。

参考过逃离沙漠 的博客,添加了

<dependency><groupId>org.springframework.bootgroupId><artifactId>spring-boot-starter-webartifactId>
dependency> 在主文件添加了

&#64;RequestMapping("/hello")&#64;ResponseBodyString home() {return "Hello ,spring boot!";} 具体看他的示例就可以&#xff0c;启动正常。

localhost:8080/hello访问正常&#xff0c;那么说明官方示例是正常的。

启动信息如下&#xff0c;就自动停止了&#xff0c;也没报错。

. ____ _ __ _ _/\\ / ___&#39;_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | &#39;_ | &#39;_| | &#39;_ \/ _&#96; | \ \ \ \\\/ ___)| |_)| | | | | || (_| | ) ) ) )&#39; |____| .__|_| |_|_| |_\__, | / / / /&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;|_|&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;|___/&#61;/_/_/_/:: Spring Boot :: (v1.5.9.RELEASE)2017-12-23 23:50:04.031 INFO 6292 --- [ main] c.c.c.s.SpringbootDemoApplication : Starting SpringbootDemoApplication on Jesse-PC with PID 6292 (D:\workspace-eclipse\springboot-demo\target\classes started by acer in D:\workspace-eclipse\springboot-demo)
2017-12-23 23:50:04.031 INFO 6292 --- [ main] c.c.c.s.SpringbootDemoApplication : No active profile set, falling back to default profiles: default
2017-12-23 23:50:04.126 INFO 6292 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext&#64;5c18298f: startup date [Sat Dec 23 23:50:04 CST 2017]; root of context hierarchy
2017-12-23 23:50:04.921 INFO 6292 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-12-23 23:50:04.937 INFO 6292 --- [ main] c.c.c.s.SpringbootDemoApplication : Started SpringbootDemoApplication in 1.28 seconds (JVM running for 1.864)
2017-12-23 23:50:04.937 INFO 6292 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext&#64;5c18298f: startup date [Sat Dec 23 23:50:04 CST 2017]; root of context hierarchy
2017-12-23 23:50:04.937 INFO 6292 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
但可以看到第一行&#xff1a;Starting SpringbootDemoApplication on Jesse-PC with PID 6292 (D:\workspace-eclipse\springboot-demo\target\classes started by acer in D:\workspace-eclipse\springboot-demo)

狗日的跑到了target/class下去读取SpringbootDemoApplication&#xff0c;导进来的项目target目录下是空的&#xff0c;那就按套路来打包吧。

项目右键Run As/Maven Build...  

Base directory为${project_loc:springboot-demo} 其中springboot-demo为项目名称。

Goals为package或者clean package -Dmaven.test.skip&#61;true均可&#xff0c;只是前者会多generated-tesrt-sources和surefire-reports&#xff0c;具体


打包好后&#xff0c;刷新项目&#xff0c;target目录下为打包生成的文件


发现target下还是没有class目录呀&#xff0c;那就姑且不管&#xff0c;直接运行jar包启动项目吧。

java -jar springboot-demo-0.0.1-SNAPSHOT.jar > log.file 2>&1 &
访问localhost:8080&#xff0c;页面一闪而过。在target下生成的log.file可以看到启动信息&#xff0c;如上只是到springboot-demo-0.0.1-SNAPSHOT.jar里去读取文件了。
&#xff08;发现了个有趣的事情是&#xff0c;在eclipse中target下没有class目录&#xff0c;而在工作空间的该项目target下是有class目录的。/无语。&#xff09;

实际还是跟上面一样&#xff0c;启动后自动熄火了。
在写这篇文章前是在cmd下启动&#xff0c;发现eclipse下项目启动了&#xff0c;当时莫名其妙的&#xff0c;我实在cmd下的控制台直接启动的jar包啊。

最后发现pom.xml中加上

org.springframework.bootspring-boot-starter-web可在eclipse运行SpringbootDemoApplication启动项目。http://localhost:8080/报404&#xff0c;加个返回结果就好了。

至此SpringBoot的第一个例子也算是跑起来了。跑步起来的原因肯定是由于&#64;SpringBootApplication注解的特殊性&#xff0c;暂时就不深入了解了。

最终pom.xml如下&#xff1a;


4.0.0com.chensan.cdssspringboot-demo0.0.1-SNAPSHOTjarspringboot-demoDemo project for Spring Bootorg.springframework.bootspring-boot-starter-parent1.5.9.RELEASE UTF-8UTF-81.8org.springframework.bootspring-boot-starterorg.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-testtestorg.springframework.bootspring-boot-maven-plugin
主文件&#xff1a;

package com.chensan.cdss.springbootdemo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;&#64;Controller
&#64;SpringBootApplication
public class SpringbootDemoApplication {&#64;RequestMapping("/hello")&#64;ResponseBodyString home() {return "Hello ,spring boot!";}public static void main(String[] args) {SpringApplication.run(SpringbootDemoApplication.class, args);}
}

访问&#xff1a;http://localhost:8080/hello 效果如下




推荐阅读
  • Nginx使用AWStats日志分析的步骤及注意事项
    本文介绍了在Centos7操作系统上使用Nginx和AWStats进行日志分析的步骤和注意事项。通过AWStats可以统计网站的访问量、IP地址、操作系统、浏览器等信息,并提供精确到每月、每日、每小时的数据。在部署AWStats之前需要确认服务器上已经安装了Perl环境,并进行DNS解析。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • 在重复造轮子的情况下用ProxyServlet反向代理来减少工作量
    像不少公司内部不同团队都会自己研发自己工具产品,当各个产品逐渐成熟,到达了一定的发展瓶颈,同时每个产品都有着自己的入口,用户 ... [详细]
  • Imtryingtofigureoutawaytogeneratetorrentfilesfromabucket,usingtheAWSSDKforGo.我正 ... [详细]
  • Spring常用注解(绝对经典),全靠这份Java知识点PDF大全
    本文介绍了Spring常用注解和注入bean的注解,包括@Bean、@Autowired、@Inject等,同时提供了一个Java知识点PDF大全的资源链接。其中详细介绍了ColorFactoryBean的使用,以及@Autowired和@Inject的区别和用法。此外,还提到了@Required属性的配置和使用。 ... [详细]
  • 本文记录了在vue cli 3.x中移除console的一些采坑经验,通过使用uglifyjs-webpack-plugin插件,在vue.config.js中进行相关配置,包括设置minimizer、UglifyJsPlugin和compress等参数,最终成功移除了console。同时,还包括了一些可能出现的报错情况和解决方法。 ... [详细]
  • 本文讨论了如何使用Web.Config进行自定义配置节的配置转换。作者提到,他将msbuild设置为详细模式,但转换却忽略了带有替换转换的自定义部分的存在。 ... [详细]
  • 这是原文链接:sendingformdata许多情况下,我们使用表单发送数据到服务器。服务器处理数据并返回响应给用户。这看起来很简单,但是 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • 本文介绍了Web学习历程记录中关于Tomcat的基本概念和配置。首先解释了Web静态Web资源和动态Web资源的概念,以及C/S架构和B/S架构的区别。然后介绍了常见的Web服务器,包括Weblogic、WebSphere和Tomcat。接着详细讲解了Tomcat的虚拟主机、web应用和虚拟路径映射的概念和配置过程。最后简要介绍了http协议的作用。本文内容详实,适合初学者了解Tomcat的基础知识。 ... [详细]
  • WebSocket与Socket.io的理解
    WebSocketprotocol是HTML5一种新的协议。它的最大特点就是,服务器可以主动向客户端推送信息,客户端也可以主动向服务器发送信息,是真正的双向平等对话,属于服务器推送 ... [详细]
  • 本文讨论了在openwrt-17.01版本中,mt7628设备上初始化启动时eth0的mac地址总是随机生成的问题。每次随机生成的eth0的mac地址都会写到/sys/class/net/eth0/address目录下,而openwrt-17.01原版的SDK会根据随机生成的eth0的mac地址再生成eth0.1、eth0.2等,生成后的mac地址会保存在/etc/config/network下。 ... [详细]
  • web.py开发web 第八章 Formalchemy 服务端验证方法
    本文介绍了在web.py开发中使用Formalchemy进行服务端表单数据验证的方法。以User表单为例,详细说明了对各字段的验证要求,包括必填、长度限制、唯一性等。同时介绍了如何自定义验证方法来实现验证唯一性和两个密码是否相等的功能。该文提供了相关代码示例。 ... [详细]
  • 深入理解Kafka服务端请求队列中请求的处理
    本文深入分析了Kafka服务端请求队列中请求的处理过程,详细介绍了请求的封装和放入请求队列的过程,以及处理请求的线程池的创建和容量设置。通过场景分析、图示说明和源码分析,帮助读者更好地理解Kafka服务端的工作原理。 ... [详细]
  • 在springmvc框架中,前台ajax调用方法,对图片批量下载,如何弹出提示保存位置选框?Controller方法 ... [详细]
author-avatar
红台门
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有