no declaration can be found for element 'tx:annotation-driven' - java

I am using spring 4.1.1 for my project,i am getting the following exception. Given below are the definitions i am using , need help!
xmlns:tx="http://www.springframework.org/schema/tx"
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd"

Make sure that you have the spring-tx dependency on your classpath. If you are using maven add the dependency
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
If you already have the dependency check the version as it might not be 4.1.
You can also declare your namespace omitting the version so that it always picks the latest
xmlns:tx="http://www.springframework.org/schema/tx"
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"
Specify the version if you really need some feature specific to the version

Related

Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace

I am facing a lot of issues one after the other. Let me note it down properly -
I am implementing Springframework cache and this was my original SpringCacheConfig.xml -
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:hz="http://www.hazelcast.com/schema/spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.hazelcast.com/schema/spring http://www.hazelcast.com/schema/spring/hazelcast-spring.xsd">
This was working fine in my laptop, but in the test VM, we were not able to download the XSD schema files from internet.
So I changed the schemalocations to classpath -
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:hz="http://www.hazelcast.com/schema/spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans classpath:spring-beans.xsd
http://www.springframework.org/schema/cache classpath:spring-cache.xsd
http://www.springframework.org/schema/context classpath:spring-context.xsd
http://www.hazelcast.com/schema/spring classpath:hazelcast-spring.xsd">
So now the XSD files were picked up. But the downloaded spring-context.xsd file has the following content -
<xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="https://www.springframework.org/schema/beans/spring-beans-4.3.xsd"/>
<xsd:import namespace="http://www.springframework.org/schema/tool" schemaLocation="https://www.springframework.org/schema/tool/spring-tool-4.3.xsd"/>
So I have again moved them to classpath.
After these changes if I now execute our code, I am getting the following error -
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: class path resource [SpringCacheConfig.xml]
I tried to solve this problem by many previous posts, but not able to.
The pom is already including spring-context related jars -
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${springframework.version}</version>
</dependency>
These jars are not packaged within the main jar, but are available at
modules/system/layers/thirdparty/org/springframework/main/spring-context-4.3.1.RELEASE.jar.
But why the jar couldn't be found?
I also tried the shade plugin, but still dependency jars are not included -
How to create spring-based executable jar with maven?
What else should I think about?
I don't have the META-INF/spring.handlers etc Spring related files within the jar. Can it be the issue?
I solved the problem by creating a META-INF directory and putting the spring.handlers and spring.schemas files into it. I extracted all the spring jars, some of them have these spring.handlers and spring.schemas files. I concatenated the contents of those files and put them in META-INF.
But surprisingly, the project was working in eclipse, but not in VM. In eclipse project, I don't need to copy the spring.handlers and spring.schemas files in the jar's META-INF directory - it works without them. But in VM I need to copy the files! May be in eclipse these files are referred from .m2, since those jars are in the classpath? Any idea?
Thanks

Upgrade from spring 4.3.2 to 5.0.2 is causing missing #AliasFor error

When I try to upgrade a spring web-mvc application from version 4.3.2 to 5.0.2, I get an error in servlet xml. The error happens in the following line,
<context:component-scan base-package="com.mypackage" />
Error is as follows,
Error occured processing XML '#AliasFor declaration on attribute [value] in annotation [org.springframework.stereotype.Controller] is missing required 'attribute' value.'. See Error Log for more details
This is how my servlet xml looks like.
<?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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd">
<security:global-method-security secured-annotations="enabled"/>
<context:component-scan base-package="com.mypackage" />
<mvc:view-controller path="/" view-name="index"/>
<mvc:resources mapping="/resources/**" location="/resources/" />
</beans>
If I use 5.0.0 this error is not happening. As it is complaining about a missing annotation in org.springframework.stereotype.Controller, I tried to find out what is newly added or missing in the Controller. I could see that a new line is added in version 5.0.2 and it has a missing 'attribute'.
#AliasFor(annotation = Component.class)
I am sure I am missing something in my bean class definition which is required from version 5.0.2.
I'd check for three things.
First, you need to make sure that your dependency management is right. You can run mvn dependency:tree and check that all Spring dependencies are using the same version. If you want to avoid issues like this in the future, you can use the Spring Framework BOM and let it manage versions for Spring Framework artifacts:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${spring.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
If your dependency management is right, this might be a corrupted JAR. You can clear things and re-download dependencies with mvn dependency:purge-local-repository.
Finally, using versioned schemas in your XML is not advised anymore - in fact, it's not supported anymore as of Spring Framework 5.0, see SPR-13499.

Upgrading Spring Security 2.5 to 3.1 - java.lang.NoClassDefFoundError: org/springframework/security/Authentication

This problem is proving very tricky to resolve. Usual story, inherited a very poorly maintained java web application with no unit tests and a variety of ancient jar dependencies with no version info dumped in a lib directory built using Ant. In order to get better maintenance and understanding of the dependencies I migrated over to Maven. Subsequently, I realised the version of Spring was quite old (Spring 2.x and Spring Security 2.0.3). I upgraded successfully to Spring 2.5. I have now started migrating Spring up to 3.1.2.RELEASE, and Spring Security up to 3.1.3.RELEASE.
Everything compiles, I don't get any namespace issues either (declared in headers of Spring XML configs), but fails when being deployed as a WAR file into Tomcat Container. The log file reports:
Could not instantiate bean class [com.mydomain.repository.ReportDaoImpl]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/security/Authentication
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
I checked, and org.springframework.security.Authentication belongs to the old Spring Security jar (2.0.4)
My current Maven dependencies are as follows:
<spring.version>3.1.2.RELEASE</spring.version>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- SPRING SECURITY -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-acl</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
My security.xml is minimal:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="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-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<http auto-config='true'>
<intercept-url pattern="/**" access="ROLE_Admin" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="admin" password="password" authorities="ROLE_Admin" />
</user-service>
</authentication-provider>
</authentication-manager>
All my other Spring Config files use the following namespace headers in their configs:
<?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:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
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
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
As far as I know this application contains NO annotations regarding Spring.
So how does the Spring Security 2.0.4 class org.springframework.security.Authentication get requested by a Spring 3.1 class org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory when instantiating a DAO object (which has nothing to do with Spring security settings). It may be that the DAO is picked because it is the first bean in order to get instantiated in the applicationContext.xml by the classloader (via Spring dependency injection container) but i cannot see how there is still a reference lurking somewhere in this application to an old 2.0.4 class. Since everything compiles ok, and the Maven pom only references 3.1 my take is that there must be some configuration somewhere still trying to pull in an old class. Anyone with Spring Security knowledge (in particular upgrading a large app from a version 2 to version 3) might have hit this problem before but I couldn't find exact match via google. Thanks for any suggestions on this. Currently stumped.
Quick update:
The applicationContext.xml has the namespace header as given above and the DAO is simply referenced as follows:
<bean id="reportDao" class="com.mydomain.repository.ReportDaoImpl">
<property name="dataSource" ref="myDataSource" />
</bean>
There is really nothing more to it. The applicationContext pulls in another context file applicationContext-datasource which declares (same namespace header again as above):
<bean id="parentDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
</bean>
<bean id="myDataSource" parent="parentDataSource">
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
The ReportDao is over 1500 lines of poorly written procedural code. It is a POJO and implements rg.springframework.context.ApplicationContextAware. It also uses org.springframework.jdbc.core.support.JdbcDaoSupport for performing CRUD operations to the database.
Running mvn -X the output for dependencies (have switched to Spring [main] 3.0.7):
org.springframework:spring-webmvc:jar:3.0.7.RELEASE:compile
org.springframework:spring-asm:jar:3.0.7.RELEASE:compile
org.springframework:spring-beans:jar:3.0.7.RELEASE:compile
org.springframework:spring-expression:jar:3.0.7.RELEASE:compile
org.springframework:spring-web:jar:3.0.7.RELEASE:compile
org.springframework:spring-aop:jar:3.0.7.RELEASE:compile
aopalliance:aopalliance:jar:1.0:compile
org.springframework:spring-context:jar:3.0.7.RELEASE:compile
org.springframework:spring-context-support:jar:3.0.7.RELEASE:compile
org.springframework:spring-core:jar:3.0.7.RELEASE:compile
org.springframework:spring-tx:jar:3.0.7.RELEASE:compile
org.springframework:spring-jdbc:jar:3.0.7.RELEASE:compile
org.springframework.security:spring-security-acl:jar:3.1.3.RELEASE:compile
org.springframework.security:spring-security-config:jar:3.1.3.RELEASE:compile
org.springframework.security:spring-security-core:jar:3.1.3.RELEASE:compile
org.springframework.security:spring-security-taglibs:jar:3.1.3.RELEASE:compile
org.springframework.security:spring-security-web:jar:3.1.3.RELEASE:compile
org.springframework.security:spring-security-crypto:jar:3.1.3.RELEASE:compile
Looks ok I believe.
The only spring jars (grepped to be certain) in the WEB-INF/lib directory of the deliverable WAR file are:
./spring-aop-3.0.7.RELEASE.jar
./spring-asm-3.0.7.RELEASE.jar
./spring-beans-3.0.7.RELEASE.jar
./spring-context-3.0.7.RELEASE.jar
./spring-context-support-3.0.7.RELEASE.jar
./spring-core-3.0.7.RELEASE.jar
./spring-expression-3.0.7.RELEASE.jar
./spring-jdbc-3.0.7.RELEASE.jar
./spring-security-acl-3.1.3.RELEASE.jar
./spring-security-config-3.1.3.RELEASE.jar
./spring-security-core-3.1.3.RELEASE.jar
./spring-security-crypto-3.1.3.RELEASE.jar
./spring-security-taglibs-3.1.3.RELEASE.jar
./spring-security-web-3.1.3.RELEASE.jar
./spring-tx-3.0.7.RELEASE.jar
./spring-web-3.0.7.RELEASE.jar
./spring-webmvc-3.0.7.RELEASE.jar
Again, looks sensible.
Grepping the source code for "Authentication" did not help. This looks like a transitive runtime dependency issue. It goes unnoticed at compilation and isn't declared anywhere as a first level dependency. But somehow at runtime (in the Tomcat 6 container) when deployed a rogue reference to an old library file is requested.
Going to delete my Tomcat instance and start from scratch just as a precaution.
Ok, finally solved this particular problem. NoClassDefFoundError is exactly what it says on the tin. As Luke Taylor asked "Are you absolutely sure you recompiled?" Well, yes and no. I definitely recompiled, cleaned target (using Maven) etc. And the first time I used a decompiler to see the source for the generated class "XXXDao" I saw my changes. But I also noticed that when I added / removed a couple of lines from the java source, the error in the stacktrace remained on the same (random) line number. That explained I was getting a stale .class file somehow. Turns out, Maven and / or Eclipse (m2eclipse plugin) somehow managed to compile class files into the WEB-INF/classes directory of my core project (not target) and was non-deterministically overwriting the WEB-INF/classes directory in target with some classes. Even stranger, it ALWAYS deployed the old classes when compressing the classes into .WAR. So you have a case of the exploded contents looking correct but actually the compresssed WAR file with different classes.
Lesson learnt - if you get this sort of behaviour, double check the compilation steps, and try to find out how perhaps an old class file (referencing the old Authentication class) has gotten into your new build. Thanks for the pointers from those that contributed to the post!

org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict

org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'drools:grid-node'.
I'm getting this error when I add a grid-node and ksession to my spring xml. I did some searching and looks like it a classpath issue. What dependency am I missing here ?
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:drools="http://drools.org/schema/drools-spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://drools.org/schema/drools-spring org/drools/container/spring
http://drools.org/schema/drools-spring org/drools/container/spring/drools-spring-1.2.0.xsd">
<drools:grid-node id="node1"/>
<drools:ksession id="ksession1" type="stateful" kbase="kbase1" node="node1" />
My pom.xml has the following for Drools.
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-camel</artifactId>
<version>${drools.version}</version>
<exclusions>
<!-- This ensures that we use the latest version of Spring jars and not
the one that comes with drools.version. -->
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
</exclusion>
<exclusion>
<artifactId>camel-xstream</artifactId>
<groupId>org.apache.camel</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>knowledge-api</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.drools</groupId>
<artifactId>drools-spring</artifactId>
<version>${drools.version}</version>
</dependency>
This error is being issued because the Drools XSD can't be located. In this comment in the Drools user list, it is stated that the XSD's aren't publicly available, and the xsi:schemaLocation attribute in the XML is mapping that XSD to http://drools.org/schema/drools-spring org/drools/container/spring/drools-spring-1.2.0.xsd, which doesn't resolve to the proper XSD.
Spring should be automatically handling the XSD resolution given the xmlns:drools="http://drools.org/schema/drools-spring" attribute. One of the Drools JARs should be including a META-INF/spring.handlers file defining the XSD mapping for the drools namespace. Something along the lines of :
http://drools.org/schema/drools-spring=some.classpath.visible.package.xsdfile.xsd
Which should be automatically handling the XSD file included in the Drools JARs.
Try removing the last two lines of your xsi:schemaLocation attribute in order to let Spring automatically resolve the XSD.
Some related links:
Spring schemaLocation fails when there is no internet connection. Specially David Resnick's answer.
Spring reference's Appendix D.5 Registering the handler and the schema.
Of course, you could also extract that XSD from the JAR file, place it in an accessible directory from your classpath and use a classpath relative URL in xsi:schemaLocation.
By the way, it's probably a copy&paste error, but your <beans> element is missing its closing tag.
EDIT : It seems that Drools wasn't providing the spring.handlers properly (at least as of December 2010, see Drools + Spring without internet ). You might need to dig through the JARs to get the XSD and reference it directly in xsi:schemaLocation.
As for the error marker in Eclipse: I have only a workaround, and I doubt that there is a real solution for this.
As Xavi Lopez stated in his accepted answer, there is a spring-handlers file in the drools-spring jar (for me, drools-spring-5.3.0.Final.jar), under META-INF. This, however, does not reference an xsd file (although the xsd files reside in this very jar), but contains this:
http\://drools.org/schema/drools-spring=org.drools.container.spring.namespace.SpringDroolsHandler
http\://drools.org/schema/drools-spring-1.2.0=org.drools.container.spring.namespace.SpringDroolsHandler
http\://drools.org/schema/drools-spring-1.3.0=org.drools.container.spring.namespace.SpringDroolsHandler
http\://drools.org/schema/drools-spring-1.4.0=org.drools.container.spring.namespace.SpringDroolsHandler
http\://drools.org/schema/drools-spring-1.5.0=org.drools.container.spring.namespace.SpringDroolsHandler
As you can see, it defines a handler class for each version of the xsd. This works well with spring at runtime, but I never saw it working with any version of Eclipse (nor the Spring Tool Suite).
I always end up turning off validation for xsd files in the project, which - for your convenience - goes like this:
Select your project in Package Explorer, click File/Properties (or press Alt+Enter)
In the Properties for project dialog, select Validation
Check Enable project specific settings (disable the validation only for this project)
Uncheck Manual and Build for: XML Schema Validator
Press OK
Right-click on the project and select Validate (to revalidate the project with the modified settings)
(I also tried to reference the xsd directly from the spring beans definition xml, but it did not work. As the handler defined in the spring-handlers file works at runtime, this would not be a better workaround IMHO.)

Configuring drools and maven and writing hello world application using them

I want to learn drools and maven can any one help me with the links for configuring drools and maven and writing a basic hello world example using them.
Thanks in advance
You should first read the manual, then try google it. There have also been questions like this asked before, for example: How to deploy Drools Flow and rules by my web application
But anyways. This is how to integrate it if you use Maven and Spring:
you first need to include Drools dependencies:
<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.drools</groupId>
<artifactId>drools-spring</artifactId>
<version>${drools.version}</version>
</dependency>
Define the application context:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:drools="http://drools.org/schema/drools-spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://drools.org/schema/drools-spring http://drools.org/schema/drools-spring.xsd">
<drools:kbase id="kbase1">
<drools:resources>
<drools:resource source="classpath:Sample.drl" />
</drools:resources>
</drools:kbase>
<drools:ksession id="ksession1" type="stateful" kbase="kbase1" />
</beans>
Then you can inject ksession1 as a bean.
Try google: First result for Drools Maven Tutorial: http://www.installationwiki.org/Set_Up_for_JBoss_Drools.
Note that Maven is a "build" tool (actually it's more) whereas Drools is a platform/library. So using Drools does normally not depend on Maven. You might thus want to get separate tutorials.

Categories