最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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)文章

  • java讀寫串口數(shù)據(jù)你了解多少

    java讀寫串口數(shù)據(jù)你了解多少

    這篇文章主要為大家詳細(xì)介紹了java讀寫串口數(shù)據(jù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-02-02
  • 使用java一維數(shù)組模擬壓棧彈棧

    使用java一維數(shù)組模擬壓棧彈棧

    這篇文章主要介紹了如何使用java一維數(shù)組模擬壓棧彈棧,需要的朋友可以參考下
    2021-04-04
  • 使用@SpringBootTest注解進(jìn)行單元測(cè)試

    使用@SpringBootTest注解進(jìn)行單元測(cè)試

    這篇文章主要介紹了使用@SpringBootTest注解進(jìn)行單元測(cè)試,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • 解決SpringBoot使用yaml作為配置文件遇到的坑

    解決SpringBoot使用yaml作為配置文件遇到的坑

    這篇文章主要介紹了解決SpringBoot使用yaml作為配置文件遇到的坑,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • Netty分布式高性能工具類recycler的使用及創(chuàng)建

    Netty分布式高性能工具類recycler的使用及創(chuàng)建

    這篇文章主要為大家介紹了Netty分布式高性能工具類recycler的使用和創(chuàng)建,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步
    2022-03-03
  • java算法導(dǎo)論之FloydWarshall算法實(shí)現(xiàn)代碼

    java算法導(dǎo)論之FloydWarshall算法實(shí)現(xiàn)代碼

    這篇文章主要介紹了算法導(dǎo)論之FloydWarshall算法實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • SpringBoot項(xiàng)目啟動(dòng)健康檢查的操作方法

    SpringBoot項(xiàng)目啟動(dòng)健康檢查的操作方法

    在現(xiàn)代的微服務(wù)架構(gòu)中,容器化技術(shù)已經(jīng)成為一種主流的部署方式,Docker 作為容器化技術(shù)的代表,提供了一種輕量級(jí)、可移植的解決方案,然而,僅僅將應(yīng)用容器化是不夠的,我們還需要確保這些容器在運(yùn)行時(shí)能夠保持健康狀態(tài),這就是健康檢查發(fā)揮作用的地方
    2024-12-12
  • java批量下載將多個(gè)文件(minio中存儲(chǔ))壓縮成一個(gè)zip包代碼示例

    java批量下載將多個(gè)文件(minio中存儲(chǔ))壓縮成一個(gè)zip包代碼示例

    在Java應(yīng)用程序中有時(shí)我們需要從多個(gè)URL地址下載文件,并將這些文件打包成一個(gè)Zip文件進(jìn)行批量處理或傳輸,這篇文章主要給大家介紹了關(guān)于java批量下載將多個(gè)文件(minio中存儲(chǔ))壓縮成一個(gè)zip包的相關(guān)資料,需要的朋友可以參考下
    2023-11-11
  • SpringMVC文件上傳請(qǐng)求問(wèn)題分析

    SpringMVC文件上傳請(qǐng)求問(wèn)題分析

    這篇文章主要介紹了SpringMVC文件上傳請(qǐng)求,我們發(fā)的請(qǐng)求默認(rèn)都是由DispatcherServlet類的doDispatch()來(lái)處理,這個(gè)方法的邏輯處理的第一步就是處理文件上傳的請(qǐng)求,我們一起來(lái)看看是怎么處理的吧
    2024-07-07
  • Spring中事務(wù)幾個(gè)常見(jiàn)的問(wèn)題解決

    Spring中事務(wù)幾個(gè)常見(jiàn)的問(wèn)題解決

    這篇文章主要介紹了Spring中事務(wù)幾個(gè)常見(jiàn)的問(wèn)題解決,事務(wù)這個(gè)概念是數(shù)據(jù)庫(kù)層面的,Spring只是基于數(shù)據(jù)庫(kù)中的事務(wù)進(jìn)行擴(kuò)展,以及提供了一些能讓程序員更新方便操作事務(wù)的方式
    2022-08-08

最新評(píng)論

渝中区| 共和县| 丹凤县| 舞阳县| 安泽县| 石林| 安龙县| 永善县| 铜陵市| 阳曲县| 揭西县| 伊春市| 嘉禾县| 伊宁县| 海晏县| 天津市| 慈溪市| 焦作市| 错那县| 理塘县| 佛教| 临安市| 九台市| 泉州市| 盘山县| 兰溪市| 文安县| 卓资县| 景宁| 鸡泽县| 防城港市| 灵宝市| 榆社县| 永善县| 本溪市| 边坝县| 静安区| 罗定市| 双桥区| 开远市| 罗平县|