Home Sprint Boot Controller method called twice
Reply: 0

Sprint Boot Controller method called twice

Sairam Kukadala
1#
Sairam Kukadala Published in 2017-11-03 17:34:18Z

I don't know what's wrong with my code, my rest service getting called twice.

Annotations in my controller class

@EnableAutoConfiguration
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.test.java")
@Controller

Here is my sample code:

Rest Service:

 @RequestMapping(value="/user", method = RequestMethod.GET)
    public String getUserDetails(ModelMap model, @RequestParam(value = "userId") String userId){
        log.info("UserId:"+userId);
        return "content_home";
    }

web.xml:

<servlet>
        <servlet-name>myappname</servlet-name>
        <servlet-class>
                       org.springframework.web.servlet.DispatcherServlet
                </servlet-class>
        <load-on-startup>1</load-on-startup>
        <multipart-config>
            <location>\\path\folder\test</location>
            <max-file-size>10240</max-file-size>
            <max-request-size>51200</max-request-size>
            <file-size-threshold>51200</file-size-threshold>
        </multipart-config>
    </servlet>

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

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/waffle-filter.xml,
            /WEB-INF/myappname-servlet.xml
            </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

I deployed this war file in tomcat8.5 server.

I tried below and all cases service is getting called twice

  1. Tried to hit the rest service from IE, Chrome, Mozilla, Postman
  2. I commented @ComponentScan(basePackages = "com.test.java") as my myappname-servlet.xml is doing a component scan but no luck.
  3. I tried with @ResponseBody in front of the return type of method - Actually this way it's getting called only once but I need to return a jsp not the body. So it won't work out.
  4. I verified network tab in developer tools, request is placed twice as below 1st. Type = Document, Initiator = other 2nd. Type= text/html, Initiator = resturl

Any suggestion or help is greatly appreciated. Thank you!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.404403 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO