Micro-mvc与springcloud整合
2019独角兽企业重金招聘Python工程师标准>>>
Micro-mvc不但可以与springmvc整合还可以与springcloud整合
Springcloud的controller层改为接口注解仍使用springcloud和springboot相关注解实现服务注册路由等配置,但controller接口上需要添加@InjectGroovy注解设置接口实现的关联groovy。
package com.nh.micro.springcloud.demo.web;import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;import com.nh.micro.service.InjectGroovy;@InjectGroovy(name="ComputeGroovy")
@RestController
public interface ComputeController {@RequestMapping(value = "/add" ,method = RequestMethod.GET)@ResponseBodypublic Integer add(@RequestParam(value="a") Integer a, @RequestParam(value="b") Integer b);}
Spring配置中使用GroovyBeanScannerConfigurer扫描controller接口
<bean class="com.nh.micro.service.GroovyBeanScannerConfigurer"><property name="scanPath" value="com.nh.micro.springcloud.demo.web"></property></bean>
ComputeController接口实现ComputeGroovy.groovy
package groovyimport javax.annotation.Resource;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestParam;
import org.apache.log4j.Logger;class ComputeGroovy {
private final Logger logger = Logger.getLogger(getClass());//@Resource(name="discoveryClient")
//public DiscoveryClient client;public Integer add(@RequestParam Integer a, @RequestParam Integer b) {//GroovyExecUtil.execGroovyRetObj("TestGroovy", "test");Integer r = a + b;System.out.println(r);//ServiceInstance instance = client.getLocalServiceInstance();//logger.info("/add, host:" + instance.getHost() + ", service_id:" + instance.getServiceId() + ", result:" + r);return r;}
}
启动DemoServiceApplication,访问http://localhost:2222/add?a=1&b=2
转载于:https://my.oschina.net/jeffreyning/blog/1608918
Micro-mvc与springcloud整合相关推荐
- SpringCloud 整合 Dubbo
目录 1.介绍 2.代码实现 2.1 抽取公共模块 2.2 改造服务提供者 2.3 改造服务消费者 3.启动测试 1.介绍 Dubbo有两种使用方式: 1.基于SOA的思想,将一个单体架构拆分为web ...
- SpringCloud 整合 Seata
<分布式事务>https://blog.csdn.net/u011060911/article/details/122210788上面的文章系统介绍了分布式事务相关的理论知识,本文则通过代 ...
- SpringCloud - 整合Nacos启动报错Consider defining a bean of type IClientConfig
SpringCloud - 整合Nacos启动报错Consider defining a bean of type IClientConfig 前言 一. 尝试解决Bug的几种不合适方案 1.1 添加 ...
- SpringCloud整合TX-LCN5.0.2使用LCN模式实现分布式事务
一.TM配置 pom.xml文件中添加依赖: <dependency><groupId>com.codingapi.txlcn</groupId><artif ...
- springcloud整合seata
springcloud整合seata 一.背景 二.项目结构 三.实现功能: 四.项目使用到的技术 五.整合步骤 1.引入spring-cloud-starter-alibaba-seata jar包 ...
- springCloud整合seata实现分布式事务
seata简介 Seata 是一款开源的分布式事务解决方案,致力于提供高性能和简单易用的分布式事务服务.Seata 将为用户提供了 AT.TCC.SAGA 和 XA 事务模式,为用户打造一站式的分布式 ...
- SpringCloud整合log4j2总结
SpringCloud整合log4j2 常用日志框架 日志门面slf4j 为什么要选用log4j2 整合步骤 常用日志框架 java.util.logging:是JDK在1.4版本中引入的Java原生 ...
- docker 安装nacos_19.SpringCloud实战项目-SpringCloud整合Alibaba-Nacos配置中心
SpringCloud实战项目全套学习教程连载中 PassJava 学习教程 简介 PassJava-Learning项目是PassJava(佳必过)项目的学习教程.对架构.业务.技术要点进行讲解. ...
- 与springcloud整合的框架源码读取入口
前提 最近开始准备系统全面的学习springcloud相关组件,过程中会记录并发表出来,今天就是从阅读源码的入口开始. 提疑 就引入一个依赖 一个注解 怎么就可以将相关功能与springcloud给整 ...
- mybaits二十七:spring, spring mvc,mybatis(ssm) 整合
配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=" ...
最新文章
- 修身论文2000字_那些没能写出毕业论文的博士生,究竟是败在了哪里?
- Halcon: 畸变矫正与标定(1)
- 线性代数---矩阵的各种问题求解方法
- C++描述杭电OJ 2020.绝对值排序 ||
- 类型 jpa mysql_Spring Boot集成JPA
- 机器学习之 特征工程
- bzoj2257瓶子与燃料——最大公约数
- ArcGIS应用视频教程(视频+PPT+实验数据)
- 顶尖、顶级、权威期刊目录
- thinkphp5实现评论回复功能
- ZYNQ启动流程分析之BootROM
- 网络钓鱼攻击技术分析及防范
- 如何找回OneNote 误删、丢失的笔记
- css图片适应盒子大小
- 为什么企业推行OEE总是坚持不下去?
- 从25岁到55岁,人生三个十年的规划和目标
- java 如何级联删除_Java学习-040-级联删除目录中的文件、目录
- 虚拟机 Win10 磁盘扩展 “文件系统的空间不足,无法...” VMware 15 C盘扩展 磁盘扩容 VMware Workstation 显示 提示
- 南方电网计算机类工资待遇,中国南方电网正式员工待遇如何好吗?
- KPI,OKR互联网人的绩效指标