SSM二:spring boot最小可运行系统

springboot本身已经封装得比较好了,所以使用它的代码也较简单:

该项目可以用于一些提供接口的情况。

两个类,一个pom.xml配置:

一个启动类:

package net.highesoft.ssm;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration 
@ComponentScan 
@EnableAutoConfiguration 
public class Application { 
    public static void main(String[] args) { 
        SpringApplication.run(Application.class); 
    } 
}
一个Controller:

package net.highesoft.ssm.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

	@RequestMapping("/")
	public Map<String,String> home() {
		Map<String,String> map=new HashMap<>();
		map.put("key", "value");
		return map;
	}

}


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>net.highersoft</groupId>
	<artifactId>ssm</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<!-- <version>1.5.2.RELEASE</version> -->
		<version>2.1.0.RELEASE</version> 
		
		<relativePath/>
	</parent>
	<dependencies>
		<!-- spring boot实现Java Web服务 -->
		
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		
		<!-- 
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.2.12</version>
		</dependency>
		 -->
		 <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
		
	
       
	</dependencies>
	
	<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

启动动Application.java后,可以浏览器输入http://localhost:8080 看到效果。



文/程忠 浏览次数:0次   2019-11-20 18:23:31

相关阅读

微信扫描-捐赠支持
加入QQ群-技术交流

评论:
点击刷新

↓ 广告开始-头部带绿为生活 ↓
↑ 广告结束-尾部支持多点击 ↑