0

I have an issue when try to access URL defined using class + method level mappings. Only method level works BUT NOT when class + method both have mappings defined.

I meant below URL works which are on METHOD level mapping only. http://localhost:7001/SpringMVCFirstApp/hi

http://localhost:7001/SpringMVCFirstApp/hello

But if I try to access CLASS + METHOD level mapping URL it does NOT work. http://localhost:7001/SpringMVCFirstApp/greet/hi

http://localhost:7001/SpringMVCFirstApp/greet/hello ......... where /greet is defined on the class level as below.

I use Spring 4.2.0, Weblogic 10.3.6 (11gR1) and Eclipse IDE.

Following .jar files added under /WEB-INF/lib folder.

commons-logging-1.2.jar
spring-beans-4.2.0.RELEASE.jar
spring-context-4.2.0.RELEASE.jar
spring-context-support-4.2.0.RELEASE.jar
spring-core-4.2.0.RELEASE.jar
spring-expression-4.2.0.RELEASE.jar
spring-web-4.2.0.RELEASE.jar
spring-webmvc-4.2.0.RELEASE.jar

My controller

package au.com.snh.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;;

@Controller
@RequestMapping("/greet")
public class HelloController {

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public ModelAndView sayHello(){
        ModelAndView model = new ModelAndView("hello");
        model.addObject("msg","Hello Spring MVC");

        return model;
    }

    @RequestMapping("/hi")
    public ModelAndView sayHi(){
        ModelAndView model = new ModelAndView("hi");
        model.addObject("msg","Hi Spring MVC");

        return model;
    }   

}

My web.xml

<?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>SpringMVCFirstApp</display-name>

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>    
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

My servlet config file

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    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
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- scan for controller -->
    <context:component-scan base-package="au.com.snh.controllers" />

    <!-- bean configuration -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

</beans>

My JSP files (hi.jsp & hello.jsp) are created under /WEB-INF/pages folder.

Now as defined above when I try to access http://localhost:7001/SpringMVCFirstApp/greet/hello then I see as below in the browser.

This is seen in the browser

And in the CONSOLE I could just see as below.

<11/08/2015 4:57:48 PM EST> <Warning> <Socket> <BEA-000449> <Closing socket as no data read from it on 127.0.0.1:64,771 during the configured idle timeout of 5 secs> 
<11/08/2015 4:57:48 PM EST> <Warning> <Socket> <BEA-000449> <Closing socket as no data read from it on 127.0.0.1:64,772 during the configured idle timeout of 5 secs>

Can someone please tell me why works on METHOD LEVEL but not when I try with CLASS+METHOD level mapping annotation.

Looking forward to getting reply.

Thanks - Hitesh

----- Original question updated on 12/Aug/2015 ----- Dear M. Deinum, As you suggested my **servlet config ** file is changed to:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!-- scan for controller -->
    <context:component-scan base-package="au.com.snh.controllers" />

    <!-- bean configuration -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

    <mvc:annotation-driven />

</beans>

Still it's not working and when I try to deploy from Eclipse it gives below error.

[ERROR] DispatcherServlet - Context initialization failed <org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/spring-servlet.xml]; nested exception is java.lang.NoSuchMethodError: org.springframework.beans.MutablePropertyValues.add(Ljava/lang/String;Ljava/lang/Object;)Lorg/springframework/beans/MutablePropertyValues;>org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/spring-servlet.xml]; nested exception is java.lang.NoSuchMethodError: org.springframework.beans.MutablePropertyValues.add(Ljava/lang/String;Ljava/lang/Object;)Lorg/springframework/beans/MutablePropertyValues;
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:402)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:316)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:282)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:126)
    at javax.servlet.GenericServlet.init(GenericServlet.java:241)
    at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:283)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.internal.StubSecurityHelper.createServlet(StubSecurityHelper.java:64)
    at weblogic.servlet.internal.StubLifecycleHelper.createOneInstance(StubLifecycleHelper.java:58)
    at weblogic.servlet.internal.StubLifecycleHelper.<init>(StubLifecycleHelper.java:48)
    at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:539)
    at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:1981)
    at weblogic.servlet.internal.WebAppServletContext.loadServletsOnStartup(WebAppServletContext.java:1955)
    at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1874)
    at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3154)
    at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1518)
    at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:484)
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
    at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
    at weblogic.application.internal.flow.ScopedModuleDriver.start(ScopedModuleDriver.java:200)
    at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:247)
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
    at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
    at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:27)
    at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:671)
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
    at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:212)
    at weblogic.application.internal.EarDeployment.activate(EarDeployment.java:59)
    at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:161)
    at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:79)
    at weblogic.deploy.internal.targetserver.BasicDeployment.activate(BasicDeployment.java:184)
    at weblogic.deploy.internal.targetserver.BasicDeployment.activateFromServerLifecycle(BasicDeployment.java:361)
    at weblogic.management.deploy.internal.DeploymentAdapter$1.doActivate(DeploymentAdapter.java:51)
    at weblogic.management.deploy.internal.DeploymentAdapter.activate(DeploymentAdapter.java:200)
    at weblogic.management.deploy.internal.AppTransition$2.transitionApp(AppTransition.java:30)
    at weblogic.management.deploy.internal.ConfiguredDeployments.transitionApps(ConfiguredDeployments.java:240)
    at weblogic.management.deploy.internal.ConfiguredDeployments.activate(ConfiguredDeployments.java:169)
    at weblogic.management.deploy.internal.ConfiguredDeployments.deploy(ConfiguredDeployments.java:123)
    at weblogic.management.deploy.internal.DeploymentServerService.resume(DeploymentServerService.java:180)
    at weblogic.management.deploy.internal.DeploymentServerService.start(DeploymentServerService.java:96)
    at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused by: java.lang.NoSuchMethodError: org.springframework.beans.MutablePropertyValues.add(Ljava/lang/String;Ljava/lang/Object;)Lorg/springframework/beans/MutablePropertyValues;
    at org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser.getContentNegotiationManager(AnnotationDrivenBeanDefinitionParser.java:373)
    at org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser.parse(AnnotationDrivenBeanDefinitionParser.java:180)
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1297)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1287)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
    ... 56 more

Does anyone have idea what is wrong?

Thanks - Hitesh

Hitesh Patel
  • 309
  • 3
  • 9
  • 1
    Add `` to your servlet config file. – M. Deinum Aug 11 '15 at 07:32
  • Hi M. Deinum, I did what you said but getting an error during deployment. [ERROR] DispatcherServlet - Context initialization failed – Hitesh Patel Aug 11 '15 at 23:34
  • Judging from the error you are mixing jars from different spring versions, don't mix versions of a framework. – M. Deinum Aug 12 '15 at 05:34
  • Hi M. Deinum, I have only those JARS as shown above. Can you tell me please why it works when I have mapping only on the METHOD & that time it does not give any such error. As soon as I added the tab in the servlet config file my app can't be deployed. Any clue? – Hitesh Patel Aug 12 '15 at 12:02
  • 1
    Trust me you are mixing versions of the framework, hence your application doesn't work. When using the defaults it uses the old `DefaultAnnotationHandlerMapping` and `AnnotationMethodHandlerAdapter` which work different as the newer `RequestMethodHandlerMapping` and `RequestMethodHandlerAdapter` which is being used when registered ``. – M. Deinum Aug 12 '15 at 12:09
  • Hi M. Deinum, you may be right but then how to solve the issue? What exactly I need to change in my code and where? Please help me as I am fed up. I have given all my code templates in the code above. Just tried Apache Tomcat 7.0 with my app & all was fine...there was surely something to do with weblogic 10.3.6. Thanks. – Hitesh Patel Aug 13 '15 at 06:45
  • If I recall correctly web logic ships with a (modified) spring version itself. You probably need to switch class loading order so that first the classes from the web-inf/lib are used. Not sure how to do that with WebLogic (probably a specific app server deployment descriptor). See http://stackoverflow.com/questions/11476874/weblogic-10-3-5-overriding-spring-version – M. Deinum Aug 13 '15 at 07:01
  • HI M.Denium, thanks a lot. Good news. You are right it has to do with weblogic deployment descriptor. So I added below tags in the weblogic-application.xml within EAR project's META-INF folder. org.apache.* org.springframework.* ALL working now...thanks for the help. – Hitesh Patel Aug 13 '15 at 12:23

2 Answers2

0

Try to do following changes :

1 . Rename your servlet config to dispatcher-servlet.xml

  1. Remove following from web.xml

    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-servlet.xml</param-value>
    </init-param>
    
ashish
  • 161
  • 1
  • 6
  • 13
  • Hi Ashish, I did what you said but still same issue. http://localhost:7001/SpringMVCFirstApp/greet/hello Error 404--Not Found From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1: 10.4.5 404 Not Found The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. If the server does not wish to make this information available to the client, the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism. – Hitesh Patel Aug 11 '15 at 23:51
  • if possible send Project Structure.Just want to make sure all the files are at right location.(if you can share code that would be great) – ashish Aug 13 '15 at 10:23
0

Finally it's working for me.

It has something to do with deployment descriptor of the Weblogic. Weblogic's own spring jars were getting conflicted with my own. So in the /META-INF/weblogic-application.xml file of EAR project I have added below tags and it started working.

weblogic-application.xml

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-application" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/javaee_5.xsd http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.3/weblogic-application.xsd">
    <!--weblogic-version:10.3.6-->
    <wls:application-param>
        <wls:param-name>webapp.encoding.default</wls:param-name>
        <wls:param-value>UTF-8</wls:param-value>
    </wls:application-param>
    <!--tell Weblogic to use your own pkgs from /WEB-INF/lib folder-->
    <wls:prefer-application-packages>
        <wls:package-name>org.apache.*</wls:package-name>
        <wls:package-name>org.springframework.*</wls:package-name>
    </wls:prefer-application-packages>
</wls:weblogic-application>
Hitesh Patel
  • 309
  • 3
  • 9