springboot学习笔记

快速搭建

springboot简单demo的构建就不多做赘述。

比较简单的方法,Fild --> new --> Project --> Spring Initializr,然后Next填写相应信息就好。


最简单的例子

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

@RestController
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @ResponseBody
    @RequestMapping
    public String test() {
        return "hello world";
    }
}

关键注解

@SpringBootApplication

点进去可以看到


@SpringBootApplication注解主要组合了@Configuration、@EnableAutoConfiguration、@ComponentScan;若不是用@SpringBootApplication,则可以在入口类上直接使用@Configuration、@EnableAutoConfiguration、@ComponentScan。

@EnableAutoConfiguration让Spring Boot根据类路径中的jar包依赖为当前项目进行自动配置。例如,添加了spring-boot-starter-web依赖,会自动添加Tomcat和Spring MVC的以来,那么Spring Boot会对Tomcat和Spring MVC进行自动配置。又如,添加了spring-boot-starter-data-jpa依赖, Spring Boot会自动进行JPA相关的配置。

Spring Boot会自动扫描@SpringBootApplication所在类的同级包以及下级包里的bean(以及@Entity的实体类)。因此通常建议入口类放置在根包下。

@RestController
@EnableTransactionManagement

@EnableTransactionManagement注解开启注解式事务的支持。该注解通知Spring被@Transactional注解的方法被事务的切面包围。这样@Transactional就可以使用了。


配置文件

Spring Boot使用一个全局配置文件application.propertites或者application.yml,放置在src/main/resources目录或者类路径的/config下。Spring Boot的全局配置文件的作用是对一些默认配置的配置值进行修改。

https://blog.csdn.net/mrluzle/article/details/79164342


日志配置



Spring Boot集成mysql


Spring Boot dubbo zk

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值