亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Springboot整合Urule的方法步驟

 更新時(shí)間:2019年05月28日 14:57:35   作者:landlord_  
這篇文章主要介紹了Springboot整合Urule的方法步驟,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

摘要:

Urule決策引擎可簡(jiǎn)化開(kāi)發(fā)校驗(yàn)、決策類代碼,底層由java語(yǔ)言實(shí)現(xiàn),可基于SpringBoot快速配置,因?yàn)閁rule工具目前為非常用工具,網(wǎng)上關(guān)于SpringBoot整合Urule資料匱乏,一直自己摸索,簡(jiǎn)單的環(huán)境搭建也費(fèi)了些功夫,遇到些坑,作此記錄

本次記錄主要記錄Urule-Serve端Urule-Client端分開(kāi)部署的模式,這種使用場(chǎng)景也會(huì)更多;嵌入式成一個(gè)項(xiàng)目的配置和Urule-Server端一致。

一、Urule-Server端:

1.1、 基于maven的SpringBoot基本環(huán)境搭建請(qǐng)參考SpringBoot教程

1.2、引入U(xiǎn)rule相關(guān)依賴,urule-console-pro,開(kāi)源版本可到https://search.maven.org

中心搜索,依賴如下:

<dependencies>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
   <groupId>com.bstek.urule</groupId>
   <artifactId>urule-console-pro</artifactId>
   <version>2.1.0</version>
   <exclusions>
    <exclusion>
     <groupId>org.slf4j</groupId>
     <artifactId>slf4j-jdk14</artifactId>
    </exclusion>
   </exclusions>
  </dependency>
  <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>servlet-api</artifactId>
   <version>2.5</version>
   <scope>provided</scope>
  </dependency>
  <dependency>
   <groupId>org.mybatis.spring.boot</groupId>
   <artifactId>mybatis-spring-boot-starter</artifactId>
   <version>1.3.1</version>
  </dependency>
  <dependency>
   <groupId>com.alibaba</groupId>
   <artifactId>druid</artifactId>
   <version>1.0.9</version>
  </dependency>
  <dependency>
   <groupId>mysql</groupId>
   <artifactId>mysql-connector-java</artifactId>
  </dependency>
 </dependencies>

1.3、配置文件:兩個(gè),appplication.yml   ,    application.properties

appplication.yml,配置數(shù)據(jù)庫(kù)信息(我們把urule項(xiàng)目存到數(shù)據(jù)庫(kù)中)

server:
 port: 8081
spring:
 application:
 name: UruleServer
 datasource:
 name: datasource
 jdbc-url: jdbc:mysql://127.0.0.1:3306/urule?useUnicode=true&characterEncoding=utf-8
 username: root
 password: 666666
 # 使用druid數(shù)據(jù)源
 type: com.alibaba.druid.pool.DruidDataSource
 driver-class-name: com.mysql.jdbc.Driver
 filters: stat
 maxActive: 20
 initialSize: 1
 maxWait: 60000
 minIdle: 1
 timeBetweenEvictionRunsMillis: 60000
 minEvictableIdleTimeMillis: 300000
 validationQuery: select 'x'
 testWhileIdle: true
 testOnBorrow: false
 testOnReturn: false
 poolPreparedStatements: true
 maxOpenPreparedStatements: 20

注意,我這此刻DataSource下不jdbc-url而不是url。根據(jù)SpringBoot版本自行調(diào)整

application.properties,配置項(xiàng)目?jī)?chǔ)存位置

#若為本地環(huán)境需配置此路徑
#urule.repository.dir=F:/EclipsePractice/03_SpringCloud/repo4rule
#若為數(shù)據(jù)庫(kù),配置此項(xiàng),兩項(xiàng)均不配則系統(tǒng)指定默認(rèn)地址
urule.repository.databasetype=mysql
urule.repository.datasourcename=datasource
ignore-unresolvable=true
order=1

1.4、初始化bean

datesource

@Configuration
public class configuration {
 @Bean
 public PropertySourcesPlaceholderConfigurer propertySourceLoader() {
  PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
  configurer.setIgnoreUnresolvablePlaceholders(true);
  configurer.setOrder(1);
  return configurer;
 }
 
  @Bean
  @ConfigurationProperties(prefix = "spring.datasource")
  public DataSource datasource() {
   return DataSourceBuilder.create().build();
  }
}

serverlet

@Component
public class URuleServletRegistration
{
 @Bean
 public ServletRegistrationBean<HttpServlet> registerURuleServlet()
 {
 return new ServletRegistrationBean(new URuleServlet(), new String[] { "/urule/*" });
 }
 }

1.5、啟動(dòng)類:

@SpringBootApplication
@ImportResource({"classpath:urule-console-context.xml"})
public class Application
{
 public static void main(String[] args)
 {
 SpringApplication.run(Application.class, args);
 }
}

二、客戶端調(diào)用:

2.1、配置類

application.yml
server:
 port: 8090
spring:
 application:
 name: UruleClient
 datasource:
 name: datasource
 url: jdbc:mysql://127.0.0.1:3306/myland?useUnicode=true&characterEncoding=utf-8
 username: root
 password: 666666
 # 使用druid數(shù)據(jù)源
 type: com.alibaba.druid.pool.DruidDataSource
 driver-class-name: com.mysql.jdbc.Driver
 filters: stat
 maxActive: 20
 initialSize: 1
 maxWait: 60000
 minIdle: 1
 timeBetweenEvictionRunsMillis: 60000
 minEvictableIdleTimeMillis: 300000
 validationQuery: select 'x'
 testWhileIdle: true
 testOnBorrow: false
 testOnReturn: false
 poolPreparedStatements: true
 maxOpenPreparedStatements: 20
urule:
 ###服務(wù)端發(fā)現(xiàn)地址
 resporityServerUrl: http://localhost:8081
 ###knowledgeUpdateCycle為0時(shí),不是檢查緩存,每次都從服務(wù)端拉取,為1時(shí),會(huì)先查找緩存
 knowledgeUpdateCycle: 1

2.2、初始化bean

@Configuration
public class RuleConfig {
 @Bean
 public PropertySourcesPlaceholderConfigurer propertySourceLoader() {
  PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
  configurer.setIgnoreUnresolvablePlaceholders(true);
  configurer.setOrder(1);
  return configurer;
 }
}

@Component
public class URuleServletRegistration {
 //此Servlet用于接收Urule服務(wù)端發(fā)布的知識(shí)包,使用開(kāi)源版本時(shí)刪除或者注釋這個(gè)bean
 @Bean
 public ServletRegistrationBean registerURuleServlet(){
  return new ServletRegistrationBean(new KnowledgePackageReceiverServlet(),"/knowledgepackagereceiver");
 }
}

2.3、controller:

@RestController
public class TestController {
@RequestMapping("/rule")
 public String getRara(@RequestParam String data)throws IOException{
   KnowledgeService knowledgeService = (KnowledgeService) Utils.getApplicationContext().getBean(KnowledgeService.BEAN_ID);
//參數(shù),Urule項(xiàng)目名/知識(shí)包名
   KnowledgePackage knowledgePackage = knowledgeService.getKnowledge("letasa/pare");
   KnowledgeSession session = KnowledgeSessionFactory.newKnowledgeSession(knowledgePackage);
   Integer integer = Integer.valueOf(data);
   Map<String, Object> param = new HashMap();
//參數(shù),var,傳入?yún)?shù),和參數(shù)庫(kù)中定義一致
   param.put("var", integer);
   session.fireRules(param);
//result,返回參數(shù),和參數(shù)庫(kù)中定義一致
   Integer result = (Integer) session.getParameter("result");
   return String.valueOf(result);
 }
}

2.4、啟動(dòng)類

@SpringBootApplication
@ImportResource({"classpath:urule-core-context.xml"})
public class Application {
 public static void main(String[] args) {
  SpringApplication.run(Application.class, args);
 }
}

Urule項(xiàng)目配置

參數(shù)庫(kù)

規(guī)則

知識(shí)包及發(fā)布

注:Rrule-pro版本支持將知識(shí)包推送給具體客戶端,客戶端使用時(shí)先調(diào)用緩存,如無(wú)緩存則再到服務(wù)端拉去。但開(kāi)源版本的Urule不支持推送,客戶端只能主動(dòng)到服務(wù)端拉去數(shù)據(jù)。

最后訪問(wèn)客戶端:http://localhost:8090/rule?data=67,或者data=25,分別得到100,20.

success!

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Spring RestTemplate簡(jiǎn)化HTTP通信實(shí)現(xiàn)功能探究

    Spring RestTemplate簡(jiǎn)化HTTP通信實(shí)現(xiàn)功能探究

    這篇文章主要為大家介紹了Spring框架中的RestTemplate,如果你是個(gè)Java程序員,那么你肯定知道Spring框架的重要性,在Spring的眾多工具中,RestTemplate是用來(lái)簡(jiǎn)化HTTP通信的一個(gè)強(qiáng)大工具
    2024-01-01
  • visual studio 2019安裝配置可編寫(xiě)c/c++語(yǔ)言的IDE環(huán)境

    visual studio 2019安裝配置可編寫(xiě)c/c++語(yǔ)言的IDE環(huán)境

    這篇文章主要介紹了visual studio 2019安裝配置可編寫(xiě)c/c++語(yǔ)言的IDE環(huán)境,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • SpringBoot自動(dòng)初始化數(shù)據(jù)庫(kù)的方法分享

    SpringBoot自動(dòng)初始化數(shù)據(jù)庫(kù)的方法分享

    我們?cè)陧?xiàng)目中應(yīng)該經(jīng)常遇到過(guò)初始化數(shù)據(jù)的場(chǎng)景,特別是項(xiàng)目部署或者交付的時(shí)候,那么有什么方式可以在項(xiàng)目啟動(dòng)的時(shí)候自動(dòng)初始化數(shù)據(jù)庫(kù)呢,下面小編就來(lái)和大家分享幾個(gè)方法吧
    2023-08-08
  • Java基礎(chǔ)篇之serialVersionUID用法及注意事項(xiàng)詳解

    Java基礎(chǔ)篇之serialVersionUID用法及注意事項(xiàng)詳解

    這篇文章主要給大家介紹了關(guān)于Java基礎(chǔ)篇之serialVersionUID用法及注意事項(xiàng)的相關(guān)資料,SerialVersionUID屬性是用于序列化/反序列化可序列化類的對(duì)象的標(biāo)識(shí)符,我們可以用它來(lái)記住可序列化類的版本,以驗(yàn)證加載的類和序列化對(duì)象是否兼容,需要的朋友可以參考下
    2024-02-02
  • Java利用深度搜索解決數(shù)獨(dú)游戲詳解

    Java利用深度搜索解決數(shù)獨(dú)游戲詳解

    數(shù)獨(dú)是一項(xiàng)非常簡(jiǎn)單的任務(wù)。玩家需要根據(jù)9×9盤(pán)面上的已知數(shù)字,推理出所有剩余空格的數(shù)字,并滿足每一行、每一列、每一個(gè)粗線宮(3*3)內(nèi)的數(shù)字均含1-9,不重復(fù)。本文將利用Java編寫(xiě)一個(gè)程序來(lái)解決給定的數(shù)獨(dú)任務(wù),感興趣的可以動(dòng)手嘗試一下
    2022-08-08
  • 詳解Java線性結(jié)構(gòu)中的鏈表

    詳解Java線性結(jié)構(gòu)中的鏈表

    除了一些算法之外,我們還有掌握一些常見(jiàn)的數(shù)據(jù)結(jié)構(gòu),比如數(shù)組、鏈表、棧、隊(duì)列、樹(shù)等結(jié)構(gòu),所以接下來(lái)就給大家詳細(xì)講解一下線性結(jié)構(gòu)中的鏈表,需要的朋友可以參考下
    2023-07-07
  • SpringBoot通過(guò)自定義注解與異步來(lái)管理日志流程

    SpringBoot通過(guò)自定義注解與異步來(lái)管理日志流程

    實(shí)現(xiàn)日志管理說(shuō)實(shí)話方式還挺多,個(gè)人使用過(guò)直接在Controller代碼里面寫(xiě)、AOP+自定義注解、ConstraintValidator。本文主要和大家講的是自定義注解與異步來(lái)管理日志流程,感興趣的可以了解一下
    2023-03-03
  • Java并發(fā)編程之Semaphore(信號(hào)量)詳解及實(shí)例

    Java并發(fā)編程之Semaphore(信號(hào)量)詳解及實(shí)例

    這篇文章主要介紹了Java并發(fā)編程之Semaphore(信號(hào)量)詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • JPA如何使用findBy方法自定義查詢

    JPA如何使用findBy方法自定義查詢

    這篇文章主要介紹了JPA如何使用findBy方法自定義查詢,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • Java集合ConcurrentHashMap詳解

    Java集合ConcurrentHashMap詳解

    ConcurrentHashMap?是?J.U.C?包里面提供的一個(gè)線程安全并且高效的?HashMap,所以ConcurrentHashMap?在并發(fā)編程的場(chǎng)景中使用的頻率比較高
    2023-01-01

最新評(píng)論