Myeclipse下使用Maven搭建spring boot项目(第二篇)
现在需要搭建spring boot框架,并实现一个HelloWorld的项目,让程序真正运行起来。
一、在pom.xml中引入spring-boot-start-parent,spring官方的叫stater poms,它可以提供dependency management,也就是依赖管理,引入以后在声明其它dependency的时候就不需要version了。
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>1.5.3.RELEASE</version>
- </parent>
二、需要在pom.xml中引入spring-boot-starter-web,spring官方解释spring-boot-start-web包含了spring webmvc和tomcat等web开发的特性。
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- </dependencies>
三、如果我们要直接Main启动spring,那么以下plugin必须要添加,否则是无法启动的。如果使用maven的spring-boot:run的话就不需要此配置。
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin </artifactId>
- </plugin>
- </plugins>
- </build>
四、下面开始写程序,我们需要一个启动类,然后在启动类声明让spring boot自动给我们配置spring需要的配置,比如:@SpringBootApplication,为了可以尽快让程序跑起来,我们简单写一个通过浏览器访问hello world字样的例子:
- @RestController
- @SpringBootApplication
- public class ExampleSpringBoot {
- @RequestMapping("/home")
- String home() {
- return "Hello World!";
- }
- public static void main(String[] args) {
- SpringApplication.run(ExampleSpringBoot.class, args);
- }
- }
其中@SpringBootApplication声明让spring boot自动给程序进行必要的配置,等价于以默认属性使用@Configuration,@EnableAutoConfiguration和@ComponentScan。
@RestController返回json字符串的数据,直接可以编写RESTFul的接口。
五、运行我们的Application,我们先介绍第一种运行方式。第一种方式特别简单:右键Run As -> Java Application。之后打开浏览器输入地址:http://127.0.0.1:8080/home 就可以看到Hello world!了。
第二种方式右键project – Run as – Maven build – 在Goals里输入spring-boot:run ,然后Apply,最后点击Run。
六、运行报错
启动时报错NoClassDefFoundError: org/apache/juli/logging/LogFactory
参见下面的解决方法:
http://blog.csdn.net/a78270528/article/details/77548779
七、完整的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/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.bocom</groupId>
- <artifactId>maventest</artifactId>
- <packaging>war</packaging>
- <version>0.0.1-SNAPSHOT</version>
- <!-- 继承父包 -->
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>1.5.3.RELEASE</version>
- <relativePath></relativePath>
- </parent>
- <name>maventest</name>
- <url>http://maven.apache.org</url>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version><!--$NO-MVN-MAN-VER$-->
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-logging-juli</artifactId>
- <version>8.0.23</version>
- </dependency>
- </dependencies>
- <build>
- <finalName>maventest</finalName>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin </artifactId>
- </plugin>
- </plugins>
- </build>
- </project>
至些,我们的Spring boot项目已经搭建完成,并成功的运行了HelloWorld的项目。
---------------------
本文来自 二一点 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/a78270528/article/details/77573818?utm_source=copy
Myeclipse下使用Maven搭建spring boot项目(第二篇)的更多相关文章
- Myeclipse下使用Maven搭建spring boot项目
开发环境:Myeclipse2017.JDK1.6.Tomcat 8.0.Myeclipse下使用Maven搭建spring boot项目,详细过程如下: 1. New -> Project.. ...
- Myeclipse下使用Maven搭建spring boot2.0项目
现在需要搭建spring boot框架,并实现一个HelloWorld的项目,让程序真正运行起来. 一.在pom.xml中引入spring-boot-start-parent,spring官方的叫st ...
- Maven 搭建spring boot多模块项目(附源码),亲测可以,感谢原创
原创地址:https://segmentfault.com/a/1190000005020589 我的DEMO码云地址,持续添加新功能: https://gitee.com/itbase/Spring ...
- Maven 搭建spring boot多模块项目
Maven 搭建spring boot多模块项目 备注:所有项目都在idea中创建 1.idea创建maven项目 1-1: 删除src,target目录,只保留pom.xml 1-2: 根目录pom ...
- Spring Boot入门(一):搭建Spring Boot项目
从本篇博客开始,我们开始进入Spring Boot的世界,它的出现使Spring的开发变得更加简洁,因此一经推出受到众多程序员的喜爱. 作为Spring Boot系列的第一篇博客,我们先来讲解下如何搭 ...
- 基于 intellij IDEA 快速搭建Spring Boot项目
在<一步步搭建 Spring Boot maven 框架的工程>一文中,已经介绍了如何使用Eclipse快速搭建Spring Boot项目.由于最近将开发工具由Eclipse ...
- 使用IDEA,Eclispe搭建Spring Boot项目
如何创建一个Spring Boot项目?这里使用maven来进行依赖管理,根据常用的IDE,可以使用IDEA.Eclipse.或者访问官方网站搭建. 项目搭建环境准备 JDK:1.8 MAVEN:3. ...
- Spring Boot系列学习文章(一) -- Intellij IDEA 搭建Spring Boot项目
前言: 最近做的一个项目是用Spring Boot来做的,所以把工作中遇到的一些知识点.问题点整理一下,做成一系列学习文章,供后续学习Spring Boot的同仁们参考,我也是第一次接触Spring ...
- Spring boot入门(一):快速搭建Spring boot项目
(一)Spring boot介绍 本部分摘自:https://www.zhihu.com/question/64671972/answer/223383505 Spring Boot是由Pivotal ...
随机推荐
- [ASP.NET]使用uploadify上传图片,并在uploadify按钮上生成预览图
目录 需求 主要代码 总结 需求 项目中有用到uploadify上传插件,给的原型就是上传成功后替换原来的图片.没办法需求在那儿,也不能修改需求吧,只能想办法解决问题了. 主要代码 修改uploadi ...
- C与C++中非常少犯的错误,犯了后却非常难找出的错误
1.continue,break类的错误(HDU1877): #include<iostream> using namespace std; int main() { int a,b,m, ...
- 【服务器防护】centos iptables 防火墙设置 mac过滤
1.阻止MAC地址为XX:XX:XX:XX:XX:XX主机的所有通信: iptables -A INPUT -s 192.168.1.21 -m mac --mac-source XX:XX:XX:X ...
- miniui前端绑定枚举值
<script type="text/javascript"> var ConvertData = { DeliveryWays: function (e, cycle ...
- AutoFac文档(转载)
目录 开始 注册组件 控制范围和生命周期 用模块结构化Autofac xml配置 与.net集成 深入理解Autofac 指导 关于 词汇表 开始 程序集 如果你正在使用Nuget包管理器,你可以通过 ...
- django Proxy models ---- 代理模式
一个proxy models 不会在数据库中创建新的表.而是与它的基类共用同一个表 1.model 的定义: from django.db import models # Create your mo ...
- php 关于日期的一些计算
1.strtotime基本使用 date_default_timezone_set('PRC'); //设置中国时区 echo "今天:", date("Y-m-d&qu ...
- Lambda编写斐波那契数列
还需要考虑溢出等问题,闲来无事写了写 Func<float, float, float> a = (arg1, arg2) => 0f;//init ; a = (lastNumbe ...
- 解决Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.-
bug: 今天做项目的时候遇到了这样一个崩溃信息: 解决Collection <__NSArrayM: 0xb550c30> was mutated while being enumera ...
- CSS 命名规范总结
CSS 命名规范总结 BEM 命名给 CSS 以及 html 提供清晰结构,命名空间提供更多信息,模块化提高代码的重用,以达到 CSS 命名语义化.可重用性高.后期维护容易.加载渲染快的要求. 首先, ...