文档章节

Maven Drools6.4.0.Final和Spring 整合

I
 ID就这么长
发布于 2016/07/03 01:23
字数 767
阅读 499
收藏 7

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.myproject.drools</groupId>
 <artifactId>droolsspring</artifactId>
 <packaging>war</packaging>
 <version>0.0.1-SNAPSHOT</version>
 <name>droolsspring Maven Webapp</name>
 <url>http://maven.apache.org</url>
   <properties>
       <drools-version>6.4.0.Final</drools-version>
       <project.tomcat.version>8.0.0-RC5</project.tomcat.version>  
   </properties>
 <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
	<dependency>
	    <groupId>org.kie</groupId>
	    <artifactId>kie-api</artifactId>
	    <version>${drools-version}</version>
	</dependency>
	<dependency>
	    <groupId>org.kie</groupId>
	    <artifactId>kie-internal</artifactId>
	    <version>${drools-version}</version>
	</dependency>
	<dependency>
	    <groupId>org.drools</groupId>
	    <artifactId>drools-core</artifactId>
	    <version>${drools-version}</version>
	</dependency>
	<dependency>
	    <groupId>org.drools</groupId>
	    <artifactId>drools-compiler</artifactId>
	    <version>${drools-version}</version>
	</dependency>
	<dependency>
	    <groupId>org.kie</groupId>
	    <artifactId>kie-spring</artifactId>
	    <version>${drools-version}</version>
	</dependency>
	<dependency>
	    <groupId>org.springframework</groupId>
	    <artifactId>spring-context</artifactId>
	    <version>3.2.12.RELEASE</version>
	</dependency>
	<dependency>
	    <groupId>org.springframework</groupId>
	    <artifactId>spring-test</artifactId>
	    <version>3.2.12.RELEASE</version>
	</dependency>
	<dependency>
	    <groupId>commons-logging</groupId>
	    <artifactId>commons-logging</artifactId>
	    <version>1.2</version>
	</dependency>
	<dependency>
	    <groupId>org.springframework</groupId>
	    <artifactId>spring-web</artifactId>
	    <version>4.3.0.RELEASE</version>
	</dependency>
	<dependency>  
      <groupId>org.apache.tomcat</groupId>  
      <artifactId>tomcat-servlet-api</artifactId>  
      <version>${project.tomcat.version}</version>  
      <scope>provided</scope>  
    </dependency> 
  </dependencies>
  <build>
    <finalName>droolsspring</finalName>
    <plugins>  
       <plugin>  
           <groupId>org.apache.maven.plugins</groupId>  
           <artifactId>maven-compiler-plugin</artifactId>  
           <version>3.1</version>  
           <configuration>  
               <source>1.8</source>  
               <target>1.8</target>  
           </configuration>  
       </plugin> 
       <plugin>  
            <groupId>org.apache.tomcat.maven</groupId>  
            <artifactId>tomcat7-maven-plugin</artifactId>  
            <version>2.2</version>  
            <configuration>  
                <url>http://localhost:8080/manager/text</url>  
                <path>/${project.artifactId}</path>  
            </configuration>  
        </plugin>  
        <plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-resources-plugin</artifactId>  
                <configuration>  
                    <encoding>UTF-8</encoding>  
                </configuration>  
            </plugin>  
    </plugins>  
  </build>
</project>

MessageTest.java

package com.li.mysite.model;
/**Message
***/
public class MessageTest {
    public static final int HELLO = 0;
    public static final int GOODBYE = 1;

    private String message;

    private int status;

    public String getMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getStatus() {
        return this.status;
    }

    public void setStatus(int status) {
        this.status = status;
    }
}

KieTestService.java

package com.li.mysite.service;

/**KieTestService
 * 
 */
public interface KieTestService {
    void test();
}

KieTestServiceImpl.java

package com.li.mysite.service.impl;

import com.li.mysite.model.MessageTest;
import com.li.mysite.service.KieTestService;

import org.kie.api.command.Command;
import org.kie.internal.command.CommandFactory;
import org.kie.internal.runtime.StatelessKnowledgeSession;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

/**KieTestServiceImpl
 * 
 */
@Service("kieTestServiceImpl")
public class KieTestServiceImpl implements KieTestService{

    @Resource(name = "ksessionStateless")
    private StatelessKnowledgeSession ksessionStateless;

    public void test(){
        MessageTest message = new MessageTest();
        message.setMessage("Hello World");
        message.setStatus(MessageTest.HELLO);
        try {
        	ksessionStateless.setGlobal("MessageTest", message);
        	ksessionStateless.execute(message);
            System.out.println("已执行");
        } catch (LinkageError error) {
            System.out.println("" + error.getMessage());
        } catch (Exception ex) {
            System.out.println("" + ex);
        }
    }   
}

spring-config-drools.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task"
	xmlns:kie="http://drools.org/schema/kie-spring"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
	http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd 
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd 
	http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd 
	http://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd"
	default-lazy-init="true">
	
	<kie:kmodule id="kModule">
		<kie:kbase name="kbase" packages="rules">
			<kie:ksession name="ksessionStateless" type="stateless" />
		</kie:kbase>
	</kie:kmodule>
	<bean id="kiePostProcessor" class="org.kie.spring.KModuleBeanFactoryPostProcessor" />
</beans>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"  
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xmlns:jdbc="http://www.springframework.org/schema/jdbc"  
    xmlns:cache="http://www.springframework.org/schema/cache"  
    xsi:schemaLocation="  
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context.xsd  
    http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans.xsd  
    http://www.springframework.org/schema/tx  
    http://www.springframework.org/schema/tx/spring-tx.xsd  
    http://www.springframework.org/schema/jdbc  
    http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd  
    http://www.springframework.org/schema/cache  
    http://www.springframework.org/schema/cache/spring-cache-3.1.xsd  
    http://www.springframework.org/schema/aop  
    http://www.springframework.org/schema/aop/spring-aop.xsd  
    http://www.springframework.org/schema/util  
    http://www.springframework.org/schema/util/spring-util.xsd"> 
    <import resource="classpath:spring-config-drools.xml"></import>
    <bean id="kieTestService" class="com.li.mysite.service.impl.KieTestServiceImpl">
    </bean>
</beans>

#rule.drl

package rules;
import com.li.mysite.model.MessageTest;
rule "Hello World"
    when
        messagetest:MessageTest(status == 0);
    then
        System.out.println("-------------- ");
end

drools.java

package com.li.mysite.test;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.li.mysite.service.KieTestService;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"}) 
public class drools {
//	
	@Autowired
	public KieTestService kieTestService;
	
	@Test
	public void testDrools(){
		kieTestService.test();
	}

	public KieTestService getKieTestService() {
		return kieTestService;
	}
//
	public void setKieTestService(KieTestService kieTestService) {
		this.kieTestService = kieTestService;
	}
	
}

本文转载自:http://www.cnblogs.com/asoks/p/5518167.html

I
粉丝 1
博文 12
码字总数 1066
作品 0
浦东
私信 提问
spring springmvc mybatis maven 项目整合示例-导航页面

spring原理 实践解析-简单的helloworld spring原理案例-基本项目搭建 01 spring framework 下载 官网下载spring jar包 spring原理案例-基本项目搭建 02 spring jar包详解 spring jar包的用途...

noteless
2018/06/29
0
0
spring原理案例-基本项目搭建 01 spring framework 下载 官网下载spring jar包

下载spring http://spring.io/ 最重要是在特征下面的这段话,需要注意: All avaible features and modules are described in the Modules section of the reference documentation. Their ......

noteless
2016/02/24
0
0
springmvc学习笔记(6)-springmvc整合mybatis(IDEA中通过maven构建

springmvc学习笔记(6)-springmvc整合mybatis(IDEA中通过maven构建) 标签: springmvc mybatis [TOC] 本文主要展示如何在intellij IDEA中通过maven构建springmvc+mybatis框架的开发环境。 需求...

brianway
2016/03/10
432
0
springmvc 项目完整示例02 项目创建-eclipse创建动态web项目 配置文件 junit单元测试

包结构 所需要的jar包直接拷贝到lib目录下 然后选定 build path 之后开始写项目代码 配置文件 ApplicationContext.xml

noteless
2016/02/24
0
0
springmvc 项目完整示例01 需求与数据库表设计 简单的springmvc应用实例 web项目

一个简单的用户登录系统 用户有账号密码,登录ip,登录时间 打开登录页面,输入用户名密码 登录日志,可以记录登陆的时间,登陆的ip 成功登陆了的话,就更新用户的最后登入时间和ip,同时记录一条登...

noteless
2016/02/24
0
0

没有更多内容

加载失败,请刷新页面

加载更多

基础工具类

package com.atguigu.util;import java.sql.Connection;import java.sql.SQLException;import java.util.Properties;import javax.sql.DataSource;import com.alibaba.druid......

architect刘源源
今天
43
0
P30 Pro劲敌!DxO官宣新机:排行榜又要变

5月26日晚间,DxOMark官方推特预告,将在5月27日公布一款新机型的DxOMark评分,猜猜是哪款? 网友猜想的机型有:红米K20、谷歌Pixel 3a、索尼Xperia 1、诺基亚9 PureView等。 DxOMark即将公布...

linux-tao
昨天
15
0
Ubuntu18.04.2窗口过小不能自适应(二次转载)

解决Ubuntu在虚拟机窗口不能自适应 2018年09月06日 16:20:08 起不了名儿 阅读数 855 此博文转载:https://blog.csdn.net/nuddlle/article/details/77994080(原地址) 试了很多办法这个好用 ...

tahiti_aa
昨天
2
0
死磕 java同步系列之CountDownLatch源码解析

问题 (1)CountDownLatch是什么? (2)CountDownLatch具有哪些特性? (3)CountDownLatch通常运用在什么场景中? (4)CountDownLatch的初始次数是否可以调整? 简介 CountDownLatch,可以...

彤哥读源码
昨天
6
0
Nginx提供下载apk服务

有时候我们可能需要提供文件或者其他apk下载链接,通过 nginx 配置可以很简单地实现。 server {    listen 80;    server_name download.xxx.com;    root app;    locati...

Jack088
昨天
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部