myeclipse创建springboot项目

本文详细介绍在MyEclipse中配置STS插件的过程,并指导如何设置Maven环境以支持Java 1.8。此外,还提供了创建Spring Boot项目的步骤,包括pom.xml配置、依赖引入、构建插件设置以及示例代码。

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

一.在myeclipse中配置sts插件,配好环境 , 

在maven的目录下找到settings.xml文件.找到<profiles/>标签,

在该标签内添加以下代码:

<profile>
		<id>jdk-1.8</id>
		<activation>
			<activeByDeafult>true</activeByDeafult>
			<jdk>1.8</jdk>
		</activation>
		<properties>
			<maven.compiler.source>1.8</maven.compiler.source>
			<maven.compiler.target>1.8</maven.compiler.target>
			<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
		</properties>
	</profile>

创建maven jar的工程

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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.yuming</groupId>
  <artifactId>springboot-shiro</artifactId>
  <version>0.0.1-SNAPSHOT</version>
   
   <!-- 导入springboot相关依赖 -->
   <!-- 导入父项目 -->
  <parent>
  		<groupId>org.springframework.boot</groupId>
  		<artifactId>spring-boot-starter-parent</artifactId>
  		<version>1.5.9.RELEASE</version>
  </parent>
  
  <!--  -->
  <dependencies>
  		<dependency>
  			<groupId>org.springframework.boot</groupId>
  			<artifactId>spring-boot-starter-web</artifactId>
  		</dependency>
  		
  		<!-- 必须添加该依赖,不添加该依赖,就报错,且springboot项目启动失败 -->
  		<dependency>
  			<groupId>ch.qos.logback</groupId>
  			<artifactId>logback-classic</artifactId>
  			<version>1.2.3</version>
  			<!-- <scope>test</scope> -->
  		</dependency>
  		
 
  		
  </dependencies>
  
  
  
 <!-- 部署的时候,需要该插件
 该插件的作用:可将项目打包成一个可执行的jar包
  -->
 <build>
 	<plugins>
 		<plugin>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-maven-plugin</artifactId>
 		</plugin>
 	</plugins>
 </build>
  
</project>

Application:
 

package com.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
 * @springbootApplication 标注是一个主程序类,说明这是一个springboot项目
 * @author 
 *
 */
@SpringBootApplication
public class Application {
	
	public static void main(String[] args) {
		//作用:启动springboot应用
		SpringApplication.run(Application.class, args);
	}

}

TestController:

package com.test.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class TestController {

	@ResponseBody
	@RequestMapping("/hello")
	public String hello(){
		return "Hello World!!!";
	}
	
}

后台启动:

浏览器测试:

 

使用 Spring Boot 的优势 使用 Spring Boot 开发项目,会给我们带来非常美妙的开发体验,可以从以下几个方面展开来说明 Spring Boot 让开发变得更简单 Spring Boot 对开发效率的提升是全方位的,我们可以简单做一下对比: 在没有使用 Spring Boot 之前我们开发一个 web 项目需要做哪些工作: 1)配置 web.xml,加载 Spring 和 Spring mvc 2)配置数据库连接、配置 Spring 事务 3)配置加载配置文件的读取,开启注解 4)配置日志文件 … n) 配置完成之后部署 tomcat 调试 可能你还需要考虑各个版本的兼容性,jar 包冲突的各种可行性。 那么使用 Spring Boot 之后我们需要开发一个 web 项目需要哪些操作呢? 1)登录网址 http://start.spring.io/ 选择对应的组件直接下载 2)导入项目,直接开发 上面的 N 步和下面的2步形成巨大的反差,这仅仅只是在开发环境搭建的这个方面。 Spring Boot 使测试变得更简单 Spring Boot 对测试的支持不可谓不强大,Spring Boot 内置了7种强大的测试框架: JUnit: 一个 Java 语言的单元测试框架 Spring Test & Spring Boot Test:为 Spring Boot 应用提供集成测试和工具支持 AssertJ:支持流式断言的 Java 测试框架 Hamcrest:一个匹配器库 Mockito:一个 java mock 框架 JSONassert:一个针对 JSON 的断言库 JsonPath:JSON XPath 库 我们只需要在项目中引入 spring-boot-start-test依赖包,就可以对数据库、Mock、 Web 等各种情况进行测试。 Spring Boot Test 中包含了我们需要使用的各种测试场景,满足我们日常项目的测试需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值