implement feature #29 : add @SpringRule meta annotation

pull/55/head
Mahmoud Ben Hassine 9 years ago
parent eedfaa52ec
commit 7087546e2d

@ -0,0 +1,19 @@
package org.easyrules.samples.spring;
import org.easyrules.annotation.Action;
import org.easyrules.annotation.Condition;
import org.easyrules.spring.SpringRule;
@SpringRule
public class AnotherDummyRule {
@Condition
public boolean when() {
return true;
}
@Action
public void then(){
System.out.println("Hey, I'm annotated with @SpringRule");
}
}

@ -38,6 +38,8 @@ public class Launcher {
public static void main(String[] args) throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("org/easyrules/samples/spring/application-context.xml");
RulesEngine rulesEngine = (RulesEngine) context.getBean("rulesEngine");
AnotherDummyRule rule = context.getBean(AnotherDummyRule.class);
rulesEngine.registerRule(rule);
rulesEngine.fireRules();
}

@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<context:component-scan base-package="org.easyrules.samples.spring"/>
<!-- configure rule -->
<bean id="rule" class="org.easyrules.samples.spring.DummyRule" scope="prototype"/>
@ -16,4 +20,4 @@
</property>
</bean>
</beans>
</beans>

@ -59,6 +59,11 @@
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

@ -0,0 +1,29 @@
package org.easyrules.spring;
import org.easyrules.annotation.Rule;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation that turns a POJO into:
*
* <ul>
* <li>an Easy Rules rule</li>
* <li>a Spring prototype-scoped bean</li>
* </ul>
*
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Rule
@Component
@Scope("prototype")
public @interface SpringRule {
}
Loading…
Cancel
Save