spring boot微服务搭建

1.简介

    spring主推微服务基础架构。

    概念 —— 系统功能封装单独应用程序中,通过统一资源协调可以让很多独立应用以“服务”方式灵活组合,搭建更大系统架构。

2.基础搭建
maven构建
pom.xml

<!-- 指定父级项目继承(继承父项中dependencies定义) -->
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-parent</artifactId>
    <version>1.5.4.RELEASE</version>
</parent>

<!-- spring-boot所有功能实现,以spring-boot.starter.* 格式定义 -->
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

<!-- 构建配置项 -->
<build>
    <!-- 通过扩充功能插件,实现项目打包(.jar文件) -->
    <plugins>
        <plugin>
	    <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
	</plugin>
    </plugins>
    <!-- 指定打包项目名称 -->
    <finalName>springboot1</finalName>
</build>
3.SpringBoot关键注解
        @SpringBootApplication -- 复合型注解,包含(@Configuration、@ComponentScan、@EnableWebMvc)
        @EnableAutoConfiguration -- 通过注解取代Spring配置文件,并自动扫描所有@Configration的类
@ComponentScan -- 自动扫描当前类所在所有子包中带有@Controller、@Repository、@Service、@Component注解类,自动实例化
@Bean -- 注解方式,把方法返回值或类转换成ApplicationContext中的bean
SpringMVC注解 从1.4.x之后添加新注解
@GetMapping、@PostMapping、@PutMapping、@DeleteMapping -- 简化@RequestMapping(method=....)
        @CrossOrigin解决网站间应用资源跨域问题(在Controller上添加此注解)
        @RestController注解相当于@ResponseBody + @Controller合在一起的作用。
       @EnableWebMvc -- 通过注解形式实现SpringMvc加载(WebMvcConfigurerAdapter类功能一致)
       @Configuration -- 带有@Comonent注解Spring配置类,通过扫描自动加载,初始化Spring工厂
4.SpringBoot配置文件  
 推荐使用properties文件和yaml文件: application.propertites或application.yml
     yaml : 特别适合应用程序配置文件文本格式
     name: value  # 设置普通值
        object:
        property: 值 # 设置某个对象属性值
 通过@Bean和@ConfigurationProperties(prefix="") 读取配置文件并为bean属性赋值
5.spring-boot-starater方便第三方框架工具快速整合 
 spring-boot-strater-jdbc

 # 导入对应数据库jdbc驱动
 # pom.xml添加spring-boot-strater-jdbc依赖项
 # application.yml文件中编辑

  spring:
    datasouce:
	#driverClass: com.m.jdbc.Driver ysql#这句话可省略
	url:jdbc:mysql:///xxx?useUnicode=true&characterEncoding=utf8
        username:root 
        password:root

	# 编写dao类,声明JdbcTemplate,让spring自动装配
                                                                                                                                                     未完待续。。。。。。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值