SpringBoot---入门和配置,java程序设计案例教程许敏

本文档详述了SpringBoot的入门配置,包括环境约束、主程序类、配置文件处理和编码问题。通过实例展示了如何使用@ConfigurationProperties和@Value注解从properties或yaml文件中获取值,以及@Configuration导入配置文件和@Bean注解添加组件到容器。同时,文章讨论了单元测试和JSR303校验在SpringBoot中的应用。
摘要由CSDN通过智能技术生成

微服务

==================================================================

在这里插入图片描述


环境约束

===================================================================

在这里插入图片描述


maven设置—默认使用jdk-1.8版本来编译和运行项目

============================================================================================

在这里插入图片描述

jdk-1.8

true

1.8

<maven.compiler.source>1.8</maven.compiler.source>

<maven.compiler.target>1.8</maven.compiler.target>

<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>


SpringBoot的hello world入门案例

=========================================================================================

在这里插入图片描述

1.创建maven工程


2.导入springBoot的依赖


org.springframework.boot

spring-boot-starter-parent

2.2.2.RELEASE

org.springframework.boot

spring-boot-starter-web


3.编写主程序,启动springboot应用


package com;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

//来标注一个主程序类,说明这是一个springBoot应用程序

@SpringBootApplication

public class Hello {

public static void main(String[] args)

{

//spring应用启动起来

SpringApplication.run(Hello.class,args);

}

}

4.编写相关的controller和service


package com.controller;

import org.springframework.stereotype.Controller;

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

import org.springframework.web.bind.annotation.ResponseBody;

@Controller

public class HelloController {

@ResponseBody

@RequestMapping("/hello")

public String hello()

{

return “hello world”;

}

}

5.运行主程序测试

在这里插入图片描述


6.部署,将项目打包成可执行的jar包,安装插件即可


org.springframework.boot

spring-boot-maven-plugin

在这里插入图片描述

命令行使用java -jar的命令执行这个jar包即可,记住先要来到当前jar包对应的目录,通过cd 目录路径–》来到对应目录

在这里插入图片描述


Hello World探究

====================================================&#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值