Categories
java

DWR

DWR 全称 direct web remote

可将java的一个对象当成js一个对象执行方法返回结果

可以理解为js域通向java服务端的一种RPC(远程方法调用)

技术执行流 为 js-> js 对象执行方法-> post 异步请求->DWRServlet->java 对象

中间post 异步请求与 DWRServlet 均被封装屏蔽

用户只需要调用DWRServlet 动态生成的js脚本里面生成的js对象的方法 就可以发起通讯

Categories
java

gradle compile tree

gradle import local jar as dependency

dependencies{
// 依赖某个jar文件
implementation files(‘lib/xxx.jar’)


// 依赖libs目录下所有以.jar结尾的文件
implementation fileTree(dir: ‘lib’, include: [‘.jar’])

// 依赖libs目录下除了xxx.jar以外的所有以.jar结尾的文件 implementation fileTree(dir: ‘lib’, exclude: [‘xxx.jar’], include: [‘.jar’])

}

Categories
java

aliyun maven

仓库名称阿里云仓库地址阿里云仓库地址(老版)源地址
centralhttps://maven.aliyun.com/repository/centralhttps://maven.aliyun.com/nexus/content/repositories/centralhttps://repo1.maven.org/maven2/
jcenterhttps://maven.aliyun.com/repository/publichttps://maven.aliyun.com/nexus/content/repositories/jcenterhttp://jcenter.bintray.com/
publichttps://maven.aliyun.com/repository/publichttps://maven.aliyun.com/nexus/content/groups/publiccentral仓和jcenter仓的聚合仓
googlehttps://maven.aliyun.com/repository/googlehttps://maven.aliyun.com/nexus/content/repositories/googlehttps://maven.google.com/
gradle-pluginhttps://maven.aliyun.com/repository/gradle-pluginhttps://maven.aliyun.com/nexus/content/repositories/gradle-pluginhttps://plugins.gradle.org/m2/
springhttps://maven.aliyun.com/repository/springhttps://maven.aliyun.com/nexus/content/repositories/springhttp://repo.spring.io/libs-milestone/
spring-pluginhttps://maven.aliyun.com/repository/spring-pluginhttps://maven.aliyun.com/nexus/content/repositories/spring-pluginhttp://repo.spring.io/plugins-release/
grails-corehttps://maven.aliyun.com/repository/grails-corehttps://maven.aliyun.com/nexus/content/repositories/grails-corehttps://repo.grails.org/grails/core
apache snapshotshttps://maven.aliyun.com/repository/apache-snapshotshttps://maven.aliyun.com/nexus/content/repositories/apache-snapshotshttps://repository.apache.org/snapshots/

maven 版本

<repository>
  <id>spring</id>
  <url>https://maven.aliyun.com/repository/spring</url>
  <releases>
    <enabled>true</enabled>
  </releases>
  <snapshots>
    <enabled>true</enabled>
  </snapshots>
</repository>

gradle 版本

allProjects {
  repositories {
    maven {
      url 'https://maven.aliyun.com/repository/public/'
    }
    maven {
      url 'https://maven.aliyun.com/repository/spring/'
    }
    mavenLocal()
    mavenCentral()
  }
}
Categories
java Uncategorized

activiti todo

流程定义模块-> 设计-> 部署 删除

流程定义历史模块

流程实例模块

任务实例模块

Categories
java

spring activiti starter

<dependency>
    <groupId>org.activiti</groupId>
    <artifactId>activiti-spring-boot-starter</artifactId>
    <version>7.1.0.M6</version>
</dependency>

注入activiti 组件


初始化activiti 表

以下单元测试用例 用来初始化 activiti 表
@SpringBootTest
class ActivitiApplicationTests {

    @Test
    void contextLoads() {
        ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
        processEngineConfiguration.buildProcessEngine();
    }

}

activiti.cfg.xml 是在类目录下的 一个spring beans 配置文件

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd">


    <bean id="dataSource" class="com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceWrapper" >
        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://mysql.robinluo.top/activiti?characterEncoding=UTF-8&amp;nullCatalogMeansCurrent=true&amp;serverTimezone=GMT&amp;useSSL=false" />
        <property name="username" value="admin" />
        <property name="password" value="RobinLuo@2021" />
    </bean>


    <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
        <!-- ... -->
        <property name="databaseSchemaUpdate" value="true" />
        <property name="dataSource" ref="dataSource" />
    </bean>

</beans>
Categories
java

Druid Spring Starter

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.2.8</version>
</dependency>


自动注入druid datasource 
Categories
java

idea 技巧

当命令行过长

在.idea/workspaces.xml中

修改

<component name=”propertiesComponent”>

<properties name=”dynamic.classpath” value=”true” />

</component>

Categories
java

spring cloud gateway

spring cloud gateway 是微服务常用网关

网关转发语法

application.properties


spring.cloud.gateway.routes[0].id=url-proxy
spring.cloud.gateway.routes[0].predicates[0]=Path=/**
spring.cloud.gateway.routes[0].uri=http://www.baidu.com
spring.cloud.gateway.routes[0].order=1000000



spring.cloud.gateway.routes[1].id=eureka
spring.cloud.gateway.routes[1].predicates[0]=Host=eureka.robinluo.top
spring.cloud.gateway.routes[1].uri=http://localhost:8765
spring.cloud.gateway.routes[1].order=10000

order 越小 优先级越大

predicates 语法:

After=2018-01-20T06:06:06+08:00[Asia/Shanghai]

请求时间过滤 之后

Before=2018-01-20T06:06:06+08:00[Asia/Shanghai]

请求时间过滤 之前

Between=2018-01-20T06:06:06+08:00[Asia/Shanghai], 2019-01-20T06:06:06+08:00[Asia/Shanghai]

请求时间之间

Cookie=ityouknow, kee.e

cookie 匹配

Header=X-Request-Id, \d+

header 匹配

Host=**.ityouknow.com

域名匹配

Method=GET

请求方式匹配

Path=/foo/{segment}

访问路径匹配

Query=smile

请求参数匹配

RemoteAddr=192.168.1.1/24

ip地址匹配

代码分析

所有predicate 都是继承自org.springframework.cloud.gateway.handler.predicate.RoutePredicateFactory 接口的实现类

After = AfterRoutePredicateFactory

Before = BeforeRoutePredicateFactory

Between = BetweenRoutePredicateFactory

Cookie = CookieRoutePredicateFactory

Header = HeaderRoutePredicateFactory

Host = HostRoutePredicateFactory

Method = MethodRoutePredicateFactory

Path = PathRoutePredicateFactory

ReadBody = ReadBodyRoutePredicateFactory

Query = QueryRoutePredicateFactory

RemoteAddr = RemoteAddrRoutePredicateFactory

Weight = WeightRoutePredicateFactory

PredicateSpec 有所有配置语法

Categories
java

DiscoverClient ribbon Feign 服务发现与调用

服务发现是 服务治理的一个很重要的点

所有注册在服务平台的微服务 必须要能被发现 然后调用

而我们调用其他服务一般有三种方法

DiscoverClient ribbon Feign

DiscoverClient 是更加低层的方法 当DiscoverClient 需要寻找服务时 其实是向服务注册器(例如 eureka) 发送 http 请求获取躯体服务信息 包括 ip port 等

@SpringBootApplication
@EnableDiscoveryClient
class Application {

    @Autowired
    DiscoveryClient discoveryClient
}

添加了注解@EnableDiscoveryClient

然后就能自动 注入 discoverClient

 @Autowired
 DiscoveryClient discoveryClient


 def restTemplate = new RestTemplate()
 def serverList = discoveryClient.getInstances("ROBIN-ADMIN")
 println(serverList)
        restTemplate.getForObject("${serverList[0].getUri()}/api/ribbon",Map.class)

获取到discoverClient 就能通过 服务名字 查找服务实例 并且通过RestTemplate 调用服务接口了

Ribbon是调用了 discoverClient 调用服务的 但是他提供了 负载均衡功能,不显式调用某个服务实例 而是通过策略调用某类服务的其中一个 达到负载均衡效果


@SpringBootApplication
class RibbonApplication {

    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate()
    }
}

在注册RestTemplate对象时 添加LoadBalanced 注解

LoadBalanced 会自动实例化restTemplate 的服务均衡策略 具体查看LoadBalance接口 会定时ping各个服务实例 也会用譬如 回环轮询策略 寻找服务实例

当restTemplate 调用服务时 通过策略调用服务实例

restTemplate.getForObject("http://ROBIN-ADMIN/api/health",Map.class)

ROBIN-ADMIN 为某类服务的服务ID

Feign 是更加接近业务的服务调用方式

maven 添加依赖

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

添加Feign注解

@EnableFeignClients
class RibbonApplication {

}

新建接口对象

package org.robin.ribbon.feign

import org.springframework.cloud.openfeign.FeignClient
import org.springframework.web.bind.annotation.RequestMapping

@FeignClient("ROBIN-ADMIN")
interface RobinAdminService {

    @RequestMapping("/api/ribbon")
    Map ribbon()


    @RequestMapping("/api/health")
    Map health()

}

spring会自动生成 RobinAdminService

调用该对象的方法 可以 调用对应微服务的接口

Categories
java

eureka

作为微服务服务注册供应方

默认在本机 http://localhost:8761/eureka/提供服务

注册请求地址在 apps/{service-name} POST 发送本机服务信息

注销请求地址在 apps/{service-name}/{id} DELETE 发送请求

心跳请求地址在 apps/{service-name}/{id} PUT 发送请求

状态请求地址在 apps/{service-name}/{id}/status PUT 发送请求

删除状态请求地址在 apps/{service-name}/{id}/status DELETE 发送请求