urule服务端配置(包含数据库的配置):
pom文件:
4.0.0
com.bstek.urule
urule-springboot
0.0.1-SNAPSHOT
1.7
8.5.5
UTF-8
The Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0.txt
Gaojie
[email protected]
Bstek
http://www.bstek.com
https://github.com/youseries/urule.git
https://github.com/youseries/urule.git
https://github.com/youseries/urule
Bstek
http://www.bstek.com
org.springframework.boot
spring-boot-starter-parent
2.0.3.RELEASE
com.ecms
cbc.account.urule
1.0-SNAPSHOT
org.springframework.boot
spring-boot-starter-web
mysql
mysql-connector-java
5.1.40
com.alibaba
druid
1.1.10
com.bstek.urule
urule-console-pro
2.1.3
org.slf4j
slf4j-jdk14
com.bstek.urule
urule-core-pro
javax.servlet
servlet-api
2.5
provided
org.springframework.boot
spring-boot-maven-plugin
ossrh
https://oss.sonatype.org/content/repositories/snapshots
ossrh
https://oss.sonatype.org/service/local/staging/deploy/maven2
Urule Springboot Project
https://github.com/youseries/urule/tree/master/urule-springboot
https://github.com/youseries/urule/issues
Urule Springboot Project
urule-console-datasource.properties:
spring.datasource.name=mydatasource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://192.168.103.11:3306/cbc?characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true
spring.datasource.username=cbc
spring.datasource.password=cbc@20180907
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
spring.datasource.maxWait=60000
spring.datasource.timeBetweenEvictionRunsMillis=60000
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
spring.datasource.poolPreparedStatements=true
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
spring.datasource.filters=stat,wall,slf4j
application.properties:
server.port=7888
#urule.repository.dir=d:/repo
urule.repository.datasourcename=mydatasource
urule.repository.databasetype=mysql
config文件:
package com.bstek.urule.springboot;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import javax.sql.DataSource;
@Configuration
@ImportResource({"classpath:urule-console-context.xml"})
@PropertySource(value = {"classpath:urule-console-datasource.properties"})
public class Config {
/**
* PropertySourcesPlaceholderConfigurer:外部属性配置文件,可以替换xml中的属性配置,实现部分私密配置外部化,类似数据库配置
* @return
*/
@Bean
public PropertySourcesPlaceholderConfigurer propertySourceLoader(){
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
//该属性为true,将会隐藏在占位符变量无法解析或者属性文件不存在是抛出的异常
configurer.setIgnoreUnresolvablePlaceholders(true);
configurer.setOrder(1);
return configurer;
}
@Bean(name = "mydatasource")
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource(){
return DataSourceBuilder.create().type(com.alibaba.druid.pool.DruidDataSource.class).build();
}
}
对于urule需要用到的动作库,可以另外定义一个jar包,在服务端和客户端分别依赖该jar包,这样在客户端和服务端中都可以不在依赖urule的jar包。
indexServlet:
package com.bstek.urule.springboot;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author Jacky.gao
* @since 2016年10月12日
*/
public class IndexServlet extends HttpServlet {
private static final long serialVersionUID = 9155627652423910928L;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.sendRedirect(req.getContextPath()+"/urule/frame");
}
}
UruleServletRegistration:
package com.bstek.urule.springboot;
import javax.servlet.http.HttpServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import com.bstek.urule.console.servlet.URuleServlet;
/**
* @author Jacky.gao
* @since 2016年10月12日
*/
@Component
public class URuleServletRegistration {
/**
* springboot自带的支持servlet的注册方法,接收两个参数,第一个是自定义的servlet,第二个是对符合路径的访问跳转到第一个配置的servlet上
* @return
*/
@Bean
public ServletRegistrationBean registerURuleServlet(){
return new ServletRegistrationBean(new URuleServlet(),"/urule/*");
}
@Bean
public ServletRegistrationBean registerIndexServlet(){
return new ServletRegistrationBean(new IndexServlet(),"/");
}
}
活动库项目(actionRepository):
pom文件:
4.0.0
com.ecms
cbc.account.urule
1.0-SNAPSHOT
UTF-8
5.0.8.RELEASE
com.ecms
cbc-api
1.0.0-SNAPSHOT
org.springframework
spring-context
${org.springframework.version}
provided
com.alibaba
fastjson
1.2.44
org.apache.commons
commons-lang3
3.7
org.projectlombok
lombok
1.16.22
com.bstek.urule
urule-core-pro
2.1.3
org.slf4j
slf4j-jdk14
org.apache.httpcomponents
httpclient
4.5.2
sonatype
https://oss.sonatype.org/content/groups/public/
org.apache.maven.plugins
maven-source-plugin
attach-sources
jar
活动库项目为简单的java项目,只需要定义具体的方法即可,方法的写法可以参考官方网站的说明。另外urule中也可以定义通用的工具类。
客户端:
客户端pom文件:
com.ecms
cbc.account.urule
1.0-SNAPSHOT
com.bstek.urule
urule-core-pro
2.1.3
org.springframework
spring-web
org.slf4j
slf4j-jdk14
关于urule的包只需要引入core-pro和自己定义的活动库项目的jar包,core-pro中因为引入了日志和web模块,但是我的项目中自己定义了需要的相关模块,所有启动报错,同理,对不同的项目,如果产生了jar包冲突,可以自行排除。
urule.properties:
urule.knowledgeUpdateCycle=1
urule.resporityServerUrl=http://localhost:7888
里面只需要指定服务端的url和知识库的拉取策略。
UruleConfig:
package executor.config;
import com.bstek.urule.KnowledgePackageReceiverServlet;
import com.bstek.urule.URulePropertyPlaceholderConfigurer;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.io.ClassPathResource;
@Configuration
@ImportResource(locations = {"classpath:urule-core-context.xml"})
public class UruleConfig {
@Bean
public ServletRegistrationBean servletRegistrationBean(){
return new ServletRegistrationBean(new KnowledgePackageReceiverServlet(),"/knowledgepackagereceiver");
}
@Bean
public URulePropertyPlaceholderConfigurer uRuleConfig (){
URulePropertyPlaceholderConfigurer config = new URulePropertyPlaceholderConfigurer();
config.setLocation(new ClassPathResource("urule.properties"));
return config;
}
}
最后一步,在springboot的启动类中引入对自定义动作库的扫描即可。以上即为springboot整合urule的全部工作。