forked from zhoustone/middle-ware-parent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cicadasmile
committed
Oct 7, 2019
1 parent
437fea5
commit eac2c5c
Showing
22 changed files
with
703 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starters</artifactId> | ||
<version>2.0.6.RELEASE</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.drool.rule</groupId> | ||
<artifactId>ware-drool-rule</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-aop</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mybatis.spring.boot</groupId> | ||
<artifactId>mybatis-spring-boot-starter</artifactId> | ||
<version>1.3.2</version> | ||
</dependency> | ||
<!-- Mybatis --> | ||
<dependency> | ||
<groupId>com.baomidou</groupId> | ||
<artifactId>mybatis-plus-boot-starter</artifactId> | ||
<version>3.0.7.1</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>com.baomidou</groupId> | ||
<artifactId>mybatis-plus-generator</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.baomidou</groupId> | ||
<artifactId>mybatis-plus</artifactId> | ||
<version>3.0.7.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>5.1.38</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>druid-spring-boot-starter</artifactId> | ||
<version>1.1.13</version> | ||
</dependency> | ||
<!--<dependency>--> | ||
<!--<groupId>com.alibaba</groupId>--> | ||
<!--<artifactId>druid</artifactId>--> | ||
<!--<version>1.1.10</version>--> | ||
<!--</dependency>--> | ||
<dependency> | ||
<groupId>commons-lang</groupId> | ||
<artifactId>commons-lang</artifactId> | ||
<version>2.6</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.pagehelper</groupId> | ||
<artifactId>pagehelper-spring-boot-starter</artifactId> | ||
<version>1.2.3</version> | ||
</dependency> | ||
<!--drools规则引擎--> | ||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-core</artifactId> | ||
<version>7.6.0.Final</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-compiler</artifactId> | ||
<version>7.6.0.Final</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-templates</artifactId> | ||
<version>7.6.0.Final</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.kie</groupId> | ||
<artifactId>kie-api</artifactId> | ||
<version>7.6.0.Final</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.kie</groupId> | ||
<artifactId>kie-spring</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-tx</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-beans</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
<version>7.6.0.Final</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<!-- 项目构建 --> | ||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
<resources> | ||
<resource> | ||
<directory>src/main/java</directory> | ||
<includes> | ||
<include>**/*.xml</include> | ||
</includes> | ||
<filtering>false</filtering> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3.2</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
ware-drool-rule/src/main/java/com/drool/engine/Application7015.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.drool.engine; | ||
|
||
import org.mybatis.spring.annotation.MapperScan; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
@MapperScan(basePackages = {"com.drool.engine.mapper"}) | ||
public class Application7015 { | ||
public static void main(String[] args) { | ||
SpringApplication.run(Application7015.class,args) ; | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
ware-drool-rule/src/main/java/com/drool/engine/config/DruidConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.drool.engine.config; | ||
|
||
import com.alibaba.druid.pool.DruidDataSource; | ||
import com.alibaba.druid.support.http.StatViewServlet; | ||
import com.alibaba.druid.support.http.WebStatFilter; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||
import org.springframework.boot.web.servlet.ServletRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import javax.sql.DataSource; | ||
|
||
@Configuration | ||
public class DruidConfig { | ||
private static final Logger logger = LoggerFactory.getLogger(DruidConfig.class); | ||
@Value("${spring.datasource.druid.url}") | ||
private String dbUrl; | ||
@Value("${spring.datasource.druid.username}") | ||
private String username; | ||
@Value("${spring.datasource.druid.password}") | ||
private String password; | ||
@Value("${spring.datasource.druid.driverClassName}") | ||
private String driverClassName; | ||
@Value("${spring.datasource.druid.initial-size}") | ||
private int initialSize; | ||
@Value("${spring.datasource.druid.max-active}") | ||
private int maxActive; | ||
@Value("${spring.datasource.druid.min-idle}") | ||
private int minIdle; | ||
@Value("${spring.datasource.druid.max-wait}") | ||
private int maxWait; | ||
@Value("${spring.datasource.druid.pool-prepared-statements}") | ||
private boolean poolPreparedStatements; | ||
@Value("${spring.datasource.druid.max-pool-prepared-statement-per-connection-size}") | ||
private int maxPoolPreparedStatementPerConnectionSize; | ||
@Value("${spring.datasource.druid.time-between-eviction-runs-millis}") | ||
private int timeBetweenEvictionRunsMillis; | ||
@Value("${spring.datasource.druid.min-evictable-idle-time-millis}") | ||
private int minEvictableIdleTimeMillis; | ||
@Value("${spring.datasource.druid.max-evictable-idle-time-millis}") | ||
private int maxEvictableIdleTimeMillis; | ||
@Value("${spring.datasource.druid.validation-query}") | ||
private String validationQuery; | ||
@Value("${spring.datasource.druid.test-while-idle}") | ||
private boolean testWhileIdle; | ||
@Value("${spring.datasource.druid.test-on-borrow}") | ||
private boolean testOnBorrow; | ||
@Value("${spring.datasource.druid.test-on-return}") | ||
private boolean testOnReturn; | ||
@Value("${spring.datasource.druid.filters}") | ||
private String filters; | ||
@Value("{spring.datasource.druid.connection-properties}") | ||
private String connectionProperties; | ||
@Bean | ||
public DataSource dataSource() { | ||
DruidDataSource datasource = new DruidDataSource(); | ||
datasource.setUrl(dbUrl); | ||
datasource.setUsername(username); | ||
datasource.setPassword(password); | ||
datasource.setDriverClassName(driverClassName); | ||
datasource.setInitialSize(initialSize); | ||
datasource.setMinIdle(minIdle); | ||
datasource.setMaxActive(maxActive); | ||
datasource.setMaxWait(maxWait); | ||
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); | ||
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); | ||
datasource.setMaxEvictableIdleTimeMillis(maxEvictableIdleTimeMillis); | ||
datasource.setValidationQuery(validationQuery); | ||
datasource.setTestWhileIdle(testWhileIdle); | ||
datasource.setTestOnBorrow(testOnBorrow); | ||
datasource.setTestOnReturn(testOnReturn); | ||
datasource.setPoolPreparedStatements(poolPreparedStatements); | ||
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize); | ||
try { | ||
datasource.setFilters(filters); | ||
} catch (Exception e) { | ||
logger.error("druid configuration initialization filter", e); | ||
} | ||
datasource.setConnectionProperties(connectionProperties); | ||
return datasource; | ||
} | ||
@Bean | ||
public ServletRegistrationBean statViewServlet(){ | ||
ServletRegistrationBean srb = | ||
new ServletRegistrationBean(new StatViewServlet(),"/druid/*"); | ||
//设置控制台管理用户 | ||
srb.addInitParameter("loginUsername","root"); | ||
srb.addInitParameter("loginPassword","root"); | ||
//是否可以重置数据 | ||
srb.addInitParameter("resetEnable","false"); | ||
return srb; | ||
} | ||
@Bean | ||
public FilterRegistrationBean statFilter(){ | ||
//创建过滤器 | ||
FilterRegistrationBean frb = | ||
new FilterRegistrationBean(new WebStatFilter()); | ||
//设置过滤器过滤路径 | ||
frb.addUrlPatterns("/*"); | ||
//忽略过滤的形式 | ||
frb.addInitParameter("exclusions", | ||
"*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); | ||
return frb; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
ware-drool-rule/src/main/java/com/drool/engine/config/RuleEngineConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.drool.engine.config; | ||
|
||
import org.kie.api.KieBase; | ||
import org.kie.api.KieServices; | ||
import org.kie.api.builder.KieBuilder; | ||
import org.kie.api.builder.KieFileSystem; | ||
import org.kie.api.builder.KieRepository; | ||
import org.kie.api.runtime.KieContainer; | ||
import org.kie.api.runtime.KieSession; | ||
import org.kie.internal.io.ResourceFactory; | ||
import org.kie.spring.KModuleBeanFactoryPostProcessor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; | ||
import org.springframework.core.io.support.ResourcePatternResolver; | ||
import java.io.IOException; | ||
|
||
@Configuration | ||
public class RuleEngineConfig { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(RuleEngineConfig.class) ; | ||
private static final String RULES_PATH = "droolRule/"; | ||
private final KieServices kieServices = KieServices.Factory.get(); | ||
|
||
@Bean | ||
public KieFileSystem kieFileSystem() throws IOException { | ||
KieFileSystem kieFileSystem = kieServices.newKieFileSystem(); | ||
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(); | ||
Resource[] files = resourcePatternResolver.getResources("classpath*:" + RULES_PATH + "*.*"); | ||
String path = null; | ||
for (Resource file : files) { | ||
path = RULES_PATH + file.getFilename(); | ||
LOGGER.info("path="+path); | ||
kieFileSystem.write(ResourceFactory.newClassPathResource(path, "UTF-8")); | ||
} | ||
return kieFileSystem; | ||
} | ||
|
||
@Bean | ||
public KieContainer kieContainer() throws IOException { | ||
KieRepository kieRepository = kieServices.getRepository(); | ||
kieRepository.addKieModule(kieRepository::getDefaultReleaseId); | ||
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem()); | ||
kieBuilder.buildAll(); | ||
return kieServices.newKieContainer(kieRepository.getDefaultReleaseId()); | ||
} | ||
|
||
@Bean | ||
public KieBase kieBase() throws IOException { | ||
return kieContainer().getKieBase(); | ||
} | ||
|
||
@Bean | ||
public KieSession kieSession() throws IOException { | ||
return kieContainer().newKieSession(); | ||
} | ||
|
||
@Bean | ||
public KModuleBeanFactoryPostProcessor kiePostProcessor() { | ||
return new KModuleBeanFactoryPostProcessor(); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
ware-drool-rule/src/main/java/com/drool/engine/config/SpringContextUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.drool.engine.config; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class SpringContextUtil implements ApplicationContextAware { | ||
public static ApplicationContext applicationContext; | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) | ||
throws BeansException { | ||
SpringContextUtil.applicationContext = applicationContext; | ||
} | ||
|
||
public static Object getBean(String name) { | ||
return applicationContext.getBean(name); | ||
} | ||
|
||
public static <T> T getBean(String name, Class<T> requiredType) { | ||
return applicationContext.getBean(name, requiredType); | ||
} | ||
|
||
public static boolean containsBean(String name) { | ||
return applicationContext.containsBean(name); | ||
} | ||
|
||
public static boolean isSingleton(String name) { | ||
return applicationContext.isSingleton(name); | ||
} | ||
|
||
public static Class<? extends Object> getType(String name) { | ||
return applicationContext.getType(name); | ||
} | ||
} |
Oops, something went wrong.