[rules-dev] Spring support for drools-api
Geoffrey De Smet
ge0ffrey.spam at gmail.com
Sun Nov 23 06:08:26 EST 2008
Strong opinions:
org.drools.spring.SpringKnowledgeAgentFactory
should be renamed to
org.drools.spring.SpringKnowledgeAgentFactoryBean
See "All Known Implementing Classes" in:
http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/FactoryBean.html
Weak opinions:
I'd also maybe consider dropping the Spring prefix, as it's in a package
called spring?
=> org.drools.spring.KnowledgeAgentFactoryBean
How are you going to name the module? Like they do in Seam?
=> module with artifactId "drools-ioc"
See http://repository.jboss.org/maven2/org/jboss/seam/jboss-seam-ioc/
With packages like this?
org.drools.ioc
org.drools.ioc.spring
org.drools.ioc.guice
org.drools.ioc.picocontainer
...
=> org.drools.ioc.spring.KnowledgeAgentFactoryBean
It helps to understand it's purpose if it follows naming conventions of
other projects :)
With kind regards,
Geoffrey De Smet
Mark Proctor schreef:
> I've been reading about spring this weekend, in preparation of spring
> support for drools-api. My first attempt was using drools-api factories
> directly, which actually works "out of the box". Here is an example
> using the KnowledgeAgentFactory:
>
> --------beans.xml-------
> <bean id="agent1" class="org.drools.agent.KnowledgeAgentFactory"
> factory-method="newKnowledgeAgent">
> <constructor-arg type="java.lang.String" value="agent1"/>
>
> <constructor-arg type="java.util.Properties">
> <props>
> <prop
> key="file">src/main/java/org/drools/springframework/testSpring.drl</prop>
> </props>
> </constructor-arg>
> </bean>
>
> ---------testSpring.drl---------
> package org.drools.springframework
>
> rule "rule 1"
> when
> then
> System.out.println( "hello world" );
> end
> ---------test--------- Resource resource = new FileSystemResource(
> "src/main/java/org/drools/springframework/beans.xml" );
> BeanFactory factory = new XmlBeanFactory( resource );
> KnowledgeAgent agent1 = ( KnowledgeAgent ) factory.getBean( "agent1" );
> agent1.getKnowledgeBase().newStatelessKnowledgeSession().executeObject(
> "test" );
>
>
> Sow I was quite impressed how easy that was to get working, but people
> like the "Spring" way. So I made a custom SpringKnowledgeAgentFactory
> that implements FactoryBean. So now the above beans.xml can look like
> the following:
> <bean id="agent1" class="org.drools.spring.SpringKnowledgeAgentFactory">
> <property name="name" value="agent1"/>
> <property name="file"
> value="src/main/java/org/drools/spring/testSpring.drl" />
> </bean>
>
> Which is much less verbose. So I think I'll take some time tomorrow to
> do FactoryBean implementations for all main user factories from
> drools-api, shouldn't take long and then we have out of the box spring
> support. Anyone have any feedback, it seems that now that we have
> drools-api, which provides complete implementation/interface separation,
> and Spring only needs to return interfaces, this is all we need to do.
> If it's quick to do, I might have a go at doing one for Guice too.
>
> Mark
>
> _______________________________________________
> rules-dev mailing list
> rules-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-dev
>
More information about the rules-dev
mailing list