myeclipse中创建springboot项目

本文介绍了如何在myeclipse中创建一个SpringBoot项目,首先创建一个Maven Web项目,然后配置pom.xml,通过两种方式开启SpringBoot。接着创建启动类并运行,访问应用。在集成过程中遇到Bean Validation API缺失的问题,解决方案是删除Hibernate验证相关文件。此外,提供了快速构建SpringBoot项目的在线地址。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

springboot项目其实本质上是一个maven项目所以我们得先创建一个maven的web项目

1、创建一个maven项目

2、配置pom.xml

开启SpringBoot的两种方式

1)继承spring-boot-starter-parent项目

2)导入spring-boot-dependencies项目依赖SpringBoot开启的两种方式

<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.demo</groupId>
  <artifactId>springboot2</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>springboot2 Maven Webapp</name>
  <url>http://maven.apache.org</url>
  
  <!-- 1.设置spring boot的parent -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.1.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<!-- 2.导入spring boot的web支持 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
        <!-- 导入测试模块,包括JUnit、Hamcrest、Mockito。 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<!-- 3.添加Spring boot的插件 -->
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build> 
 
</project>

3、创建启动类

package com.demo.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@SpringBootApplication // Spring Boot项目的核心注解,主要目的是开启自动配置
@RestController // 默认类中的方法都会以json的格式返回
public class SpringbootApplication {

	@RequestMapping("/hello")
    @ResponseBody
    public String hello() {
        return "hello world";
    }
	
	public static void main(String[] args) {
		SpringApplication.run(SpringbootApplication.class, args);
	}
}

4、运行main方法启动springboot项目

访问http://127.0.0.1:8080/hello

下来说说集成过程中遇到的错误

***************************
APPLICATION FAILED TO START
***************************

Description:

The Bean Validation API is on the classpath but no implementation could be found

Action:

Add an implementation, such as Hibernate Validator, to the classpath
 

解决直接删掉maven本地仓库org/hibernate文件夹

快速构建springboot项目地址:https://start.spring.io/

下载导入就好了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值