here is my web.xml
<servlet>
<servlet-name>Learn</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Learn</servlet-name>
<url-pattern>/learn/*</url-pattern>
</servlet-mapping>
if i change this code
<url-pattern>/learn/*</url-pattern>
to
<url-pattern>/learn/abc/</url-pattern>
i can hit my controller code which is given as
#Controller
#RequestMapping(value = "/learn")
public class ControllerClass
{
#RequestMapping(value = "/", method = RequestMethod.GET)
public String callRequest(ModelMap model)
{
return "index";
}
#RequestMapping(value = "/abc/", method = RequestMethod.GET)
public String personController(ModelMap model)
{
return "welcome";
}
}
but i also want to hit the first method or i will add more method, which i can not achieve by
/learn/abc/
in url mapping.
so please help me out with this
pom.xml
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- spring-context which provides core functionality -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<!-- The spring-aop module provides an AOP Alliance-compliant aspect-oriented
programming implementation allowing you to define -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<!-- The spring-webmvc module (also known as the Web-Servlet module) contains
Spring’s model-view-controller (MVC) and REST Web Services implementation
for web applications -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<!-- The spring-web module provides basic web-oriented integration features
such as multipart file upload functionality and the initialization of the
IoC container using Servlet listeners and a web-oriented application context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
</dependencies>
please let me know if i missed any dependency
With this url-pattern <url-pattern>/learn/*</url-pattern> configuration, to hit your method, the url path will be: /learn/learn
The url-pattern atribute on the web.xml works like a basepath for spring's servlet. So a good option is to change your url-pattern to /* , like this:
<url-pattern>/*</url-pattern>
Or if you want some basepath, change the url pattern to something like this:
/basepath/*
And to hit your method, you need to use the path url: /basepath/learn
Related
I have this problem. I'm trying to use Jersey 2.x in order to make REST api, and I would like to use jsp pages for my template (everything without spring or springboot, I can't include them into my project). I have a maven project with this structure:
enter image description here
the pom.xml has the following dependencies:
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-mvc-jsp</artifactId>
<version>2.27</version>
</dependency>
</dependencies>
and the web.xml is:
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>testjsp</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>it.testjsp.config.JerseyConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>testjsp</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
When I run my app with tomcat, the following url
http://localhost/testjsp
redirects correctly the index.hml.
I have configured the JerseyConfig class in the following way:
#ApplicationPath("/api")
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
packages("it.testjsp.endpoints");
register(JspMvcFeature.class);
property("jersey.config.server.mvc.templateBasePath", "/WEB-INF/jsp");
}
}
In order to map all the end points exposed into that package and to use jsp pages into WEB-INF/JSP.
I have two end points:
#Path("/test")
#Produces(MediaType.APPLICATION_JSON)
public class TestEndPoint {
#GET
public Map<String, Object> testApi() {
System.out.println("test jersey 2.27");
Map<String, Object> result = new HashMap<String, Object>();
result.put("result", "test jersey 2.27");
return result;
}
}
This is inside TestEndPoint class and the application responds as I expect (http://localhost/testjsp/api/test returns the json).
The PagesEndPoint is:
#Path("/pages")
public class PagesEndPoint {
#GET
#Path("{pageName}")
public Viewable getPage(#PathParam("pageName") String pageName) {
System.out.println("Try " + pageName + ".html");
return new Viewable("/" + pageName + ".html");
}
}
But when I run the app with tomcat, I have always a 404. Is possible to use jsp (or other html pages)? What I did wrong? Thanks for the help
I'm looking at every way to try to make a request type to get to my web service created by restfull Webservice into a project with Tomcat , Maven and some servlets , but nothing I do not start by mistake does not find the resource . What am I doing wrong? I may not have configured the web.xml ? how can I do?
I put the file pom.xml below and
<dependencies>
<dependency>
<groupId>org.glassfish.metro</groupId>
<artifactId>webservices-rt</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20150729</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
</dependencies>
This is code of my web service:
#Path("ws")
public class WsUserJson {
#Context
private UriInfo context;
/**
* Creates a new instance of WsUserJson
*/
public WsUserJson() {
}
/**
* Retrieves representation of an instance of com.lillonet.testmavenservletws.WsUserJson
* #return an instance of java.lang.String
*/
#GET
#Produces("application/json")
public String getJson(#QueryParam("name") String nome) {
//TODO return proper representation object
return "{"+nome+"}";
}
/**
* PUT method for updating or creating an instance of WsUserJson
* #param content representation for the resource
* #return an HTTP response with content of the updated or created resource.
*/
#PUT
#Consumes("application/json")
public void putJson(String content) {
}
}
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
That is only a jar with a bunch of interfaces. There is no implementation. That dependency should only be used when you plan on deploying to a an EE compliant Server, like Glassfish or Wildfly. Tomcat is not an EE compliant server. It is only a Servlet container. Therefore any features you use from that javaee-web-api, you need to also include an implementation.
So for now, just get rid of it so you don't use ant classes for which there is no implementation. Then you need to decide on a JAX-RS implementation to use. For now I'll just say to use Jersey. So just add this dependency
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.22.1</version>
</dependency>
Then you need to configure the application in the web.xml. You can see here for more options. You basically want something like
<web-app>
<servlet>
<servlet-name>MyApplication</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>org.foo.myresources</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MyApplication</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
The param-value in the init-param is the package you want Jersey to scan to pick up and register all your classes annotated with #Path and #Provider. The scan is recursive, so you can list the root-most package in your project if you have your resource scattered in different packages.
From here it should work. Then for JSON/POJO support, you can just add the following dependency
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.22.1</version>
</dependency>
No extra configuration is needed for that.
I am creating simple spring-mvc application referring this url. I created maven web project by referring url.
After creating this project some default file named 'index.jpg' is generated in this project. And when I build and run this project it was shpoing content of 'index.jsp' file.
Now I edited content of pom.xml file and it looks like this:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.leader.unisys</groupId>
<artifactId>sample-application</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>sample-application Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<java.version>1.6</java.version>
<spring.version>4.0.3.RELEASE</spring.version>
<cglib.version>2.2.2</cglib.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Spring core & mvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- CGLib for #Configuration -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>${cglib.version}</version>
<scope>runtime</scope>
</dependency>
<!-- Servlet Spec -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<finalName>sample-application</finalName>
</build>
</project>
The project structure looks like as shown in the image:
Now, How can I make this project to work as per my mapping in the spring-servlet.xml file.
view resolver:
public ViewResolver getViewResolver(){
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
content from controller:
#RequestMapping(value="/")
public ModelAndView getHomePage(){
return new ModelAndView("home");
}
web xml default content:
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
I want to display home.jsp after hitting http://localhost:8080/sample-application. Can someone give me the instructions to do this. I am working with maven for first time.
Move your home.jsp under WEB-INF. And then add this line in your web.xml
<welcome-file-list>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
This <welcome-file-list> in web.xml tells the application that it has to be loaded first.
what you are asking for has nothing to do with Spring or Maven but Java EE / Web container configuration - via web.xml
Here is a link that should help ..
http://docs.oracle.com/cd/E14571_01/web.1111/e13712/configurejsp.htm#WBAPP183
Relevant parts copied over:
Welcome files are defined at the Web application level. If your server is hosting multiple Web applications, you need to define welcome files separately for each Web application. You define Welcome files using the welcome-file-list element in web.xml. (The web.xml file is located in the WEB-INF directory of your Web application.) The following is an example Welcome file configuration:
Welcome File Example
<servlet>
<servlet-name>WelcomeServlet</servlet-name>
<servlet-class>foo.bar.WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WelcomeServlet</servlet-name>
<url-pattern>*.foo</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/welcome.foo</welcome-file>
</welcome-file-list>
hope this helps.
When we start the web application, by default web container looks for the welcome-file-list present in web.xml, if the welcome-file-list does not exist in web.xml then the container will look for index.html,index.htm, and index.jsp under the web-content folder in case of a normal dynamic web project, but incase of maven project container looks under the web-app folder. Container follows the order and if the first file exists it will execute that file and if it doesn't exist, the container follows the order until the third file. If any one of the files doesn't exist container will throw a 404 error.
For reference https://www.javatpoint.com/welcome-file-list
The above flow is the same for both dynamic and maven web projects, the only thing that differs from each other is that we have a web-content folder in case of dynamic WP and a web-app folder incase of maven WP
This question already has answers here:
Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request with URI [...] in DispatcherServlet"?
(13 answers)
Closed 6 years ago.
Morning, I already checked most of the answers to this problem (No mapping found for HTTP request with URI.... in DispatcherServlet with name) and also (No mapping found for HTTP request with URI [/ChickenTest/index] in DispatcherServlet with name 'dispatcherServlet') but I'm still getting "No mapping found for HTTP request with URI [/bmoa-surrounds/bmoa] in DispatcherServlet with name 'bmoa'", so, any help whould be apreciated:
pom:
<dependencies>
<!-- Junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- Testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</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-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<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>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<!-- Log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
then my web.xml
<display-name>bmoa-surrounds</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/bmoa-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>bmoa</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>bmoa</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
my spring config file
<context:component-scan base-package="xxxx"/>
<context:annotation-config/>
<context:spring-configured/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>
and finally my controller
#Controller
public class BMOAServlet implements HttpRequestHandler {
/**
*
*/
#RequestMapping("/bmoa-surrounds/bmoa")
public void handleRequest(final HttpServletRequest request,
final HttpServletResponse response) throws ServletException,
IOException {
response.getWriter().write("result=" + handleIncomingMessage(request));
}
I'm calling "http:// localhost :8080/bmoa-surrounds/bmoa?juan=9898" but I'm still geting No mapping found for HTTP request with URI [/bmoa-surrounds/bmoa] in DispatcherServlet with name 'bmoa', any ideas? my env is java6 a deploying to jboss
also im sure that the beans are beign loaded, I got this in the server log
12:34:06,671 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-5) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#57ffa0: defining beans [BMOABussinesDelegate,properties,BMOAServlet,.........]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#122d7c6
and also this
12:34:06,753 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-5) Mapped URL path [/bmoa-surrounds/bmoa] onto handler 'BMOAServlet' 12:34:06,754 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-5) Mapped URL path [/bmoa-surrounds/bmoa.*] onto handler 'BMOAServlet' 12:34:06,755 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-5) Mapped URL path [/bmoa-surrounds/bmoa/] onto handler 'BMOAServlet'
doesnt the last one means that the mappings are loaded?? please help ;(
I'm feeling really dumb right now....at first (and thanks for the clue Angad), the url-pattern was wrong, it should point to the servlet, also, the loaded bean was BMOAServlet instead of bmoa, so when I changed the url-patter no bmoa, managed to see the error, at the end my web.xml needed to look like this:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/bmoa-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>bmoa</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>bmoa</servlet-name>
<url-pattern>/bmoa</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
and the bean class like this:
#Controller("bmoa")
public class BMOAServlet implements HttpRequestHandler {
/**
*
*/
#RequestMapping("/bmoa-surrounds/bmoa")
public void handleRequest(final HttpServletRequest request,
final HttpServletResponse response) throws ServletException,
IOException {
response.getWriter().write("result=" + handleIncomingMessage(request));
}
Now everything works smooth, I also changed the servlet class like this:
<servlet>
<servlet-name>bmoa</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
Check this config file: src\main\webapp\WEB-INF\spring\appServlet\controllers.xml
content is like:
<context:component-scan base-package="org.springframework.samples.mvc" />
is your controller in "org.springframework.samples.mvc"?
In pom.xml make sure packaging is set to war like <packaging>war</packaging> ,not to jar or any thing else.
I have a problem integrating Drools with Spring. I am trying to make a simple Hello World spring example, I reached a moment where my simple project refuses to compile.
To work with Drools annotations like #KSession I need the drools-spring package, but it seems incompatible with Spring 3. As builder I use Maven. Here is how my .pom's looks like:
<dependencies>
<!-- Drools -->
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>6.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>6.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
<version>6.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>6.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-internal</artifactId>
<version>6.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-spring</artifactId>
<version>6.0.0.Beta2</version>
</dependency>
<!-- Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
</dependencies>
I use very simple case of controller class:
#Controller
#RequestMapping(value = "/")
public class BaseController extends AbstractController {
private static final Logger log = Logger.getLogger(BaseController.class);
#Autowired
#KSession("ksession-rules")
KieSession mySession;
#RequestMapping(value = "/test")
public #ResponseBody
String test() {
Fact myFact = new Fact();
myFact.setFactNumber(20); //According to my rule when myFact.number>20
//then result will be set to "Hello World"
mySession.insert(myFact);
mySession.fireAllRules();
return myFact.getResult();
}
}
At this point I receive an error:
"The hierarchy of the type BaseController is inconsistent".
I noticed that if I remove drools-spring from the dependency list the project compiles successfully. However without that package I cannot deploy my project, because the deployer demands the drools' class responsible for interpreting #KSession and that class is located in drools-spring package.
After some investigation it appears that my Drools session configuration seems to have
nothing to do with the error above, so for the sake of succinctness I will not quote them. Instead of that I will mark that even if I don't make any modifications to the spring configuration and remove the KieSession from my example, making it a simple spring hello world example, I receive one and the same error out of my IDE (Eclipse): "The hierarchy of the type BaseController is inconsistent" and if I remove the drools-spring dependency the problem disappears.
It seems to me as dependency conflict.
Does anyone experienced similar problems with drools+spring?
Can someone suggest a solution to the problem?
Am I doing something wrong?
Thanks for the help!
After some research I found two things.
Drools' drools-spring package declares its own spring dependencies that are overriding my spring dependencies, which leads to spring malunctions. What I did is to manually remove the spring dependencies from drools-spring .pom file.
Another mistake that I had in the upper example is that I didn't have kie-spring as dependency. Kie-spring is mandatory for one drools bean KModuleBeanFactoryPostProcessor, which is responsible to read my kmodule-kbase-ksession configuration from the spring configuration.
After resolving these two problems my project compiles now and I can see in the code that KModuleBeanFactoryPostProcessor defines that my configuration is being read and analized as I expected it to be.