Springboot Urule 통합 방법 절차

8486 단어 SpringbootUrule
요약:
Urule 의사 결정 엔진 은 검사,의사 결정 류 코드 를 간소화 할 수 있 습 니 다.바 텀 은 자바 언어 로 이 루어 집 니 다.SpringBoot 를 바탕 으로 빠 른 설정 을 할 수 있 습 니 다.Urule 도 구 는 현재 매우 유용 한 도구 이기 때문에 인터넷 에서 SpringBoot 통합 Urule 에 관 한 자료 가 부족 하고 스스로 모색 해 왔 습 니 다.간단 한 환경 구축 에 도 시간 이 걸 렸 고 구 덩이 를 만 났 습 니 다.이 기록 을 작성 합 니 다.
이번 기록 은 주로 Urule-server 단 Urule-client 단 을 분리 하여 배치 하 는 모델 을 기록 하 는데 이런 사용 장면 도 더욱 많 을 것 이다.끼 워 넣 은 항목 의 설정 은 Urule-server 단 과 일치 합 니 다.
1.Urule-server 엔 드:
1.1 maven 기반 의 SpringBoot 기본 환경 구축 은 SpringBoot 튜 토리 얼 을 참고 하 시기 바 랍 니 다.
1.2.Urule 관련 의존 도 를 도입 하고 urule-console-pro,오픈 소스 버 전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.프로필:두 개,application.yml   ,    application.properties
application.yml,데이터베이스 정보 설정(우 리 는 urule 프로젝트 를 데이터베이스 에 저장 합 니 다)

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   
 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 에 서 는 url 이 아 닌 jdbc-url 이 아 닙 니 다.SpringBoot 버 전에 따라 자체 조정
application.properties,프로젝트 저장 위치 설정

#            
#urule.repository.dir=F:/EclipsePractice/03_SpringCloud/repo4rule
#     ,    ,              
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.시작 클래스:

@SpringBootApplication
@ImportResource({"classpath:urule-console-context.xml"})
public class Application
{
 public static void main(String[] args)
 {
 SpringApplication.run(Application.class, args);
 }
}
2.클 라 이언 트 호출:
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   
 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:
 ###       
 resporityServerUrl: http://localhost:8081
 ###knowledgeUpdateCycle 0 ,      ,         , 1 ,      
 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         ,               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);
//  ,Urule   /    
   KnowledgePackage knowledgePackage = knowledgeService.getKnowledge("letasa/pare");
   KnowledgeSession session = KnowledgeSessionFactory.newKnowledgeSession(knowledgePackage);
   Integer integer = Integer.valueOf(data);
   Map<String, Object> param = new HashMap();
//  ,var,    ,         
   param.put("var", integer);
   session.fireRules(param);
//result,    ,         
   Integer result = (Integer) session.getParameter("result");
   return String.valueOf(result);
 }
}
2.4.시동 류

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

매개 변수 라 이브 러 리

규칙.

지식 팩 및 발표
주:RRule-pro 버 전 은 지식 패 키 지 를 구체 적 인 클 라 이언 트 에 게 전달 하 는 것 을 지원 합 니 다.클 라 이언 트 가 사용 할 때 캐 시 를 먼저 호출 하고 캐 시가 없 으 면 서버 로 끌 어 갑 니 다.그러나 오픈 소스 버 전의 Urule 은 푸 시 를 지원 하지 않 고 클 라 이언 트 는 자발적으로 서버 에 가서 데 이 터 를 끌 어 올 릴 수 밖 에 없습니다.
마지막 방문 클 라 이언 트:http://localhost:8090/rule?data=67또는 data=25,각각 100,20 을 얻 었 습 니 다.
success!
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기