0

It's been a while and I'm updating my skills for Spring and Spring boot. To that end, I'm building a web application. Here is part of my controller:

@Controller
public class LoginController {

    @RequestMapping(value = "/validate", method= RequestMethod.GET)
    @ResponseBody
    public String validate( @RequestParam(RequestConstants.KEY_USERKEY) String userkey) {
        String result = loginService.validate(userkey)
                        ? RequestConstants.KEY_SUCCESS
                        : RequestConstants.KEY_FAILURE;

        return result;
    }

The deployment seems to be going OK, the war is named theta-server and is going into tomcat/webapps OK, so I go to my browser and enter:

http://testbox:8080/theta-server/validate?userkey=bob

and I get a 404.

I look in the logs. Initially, I had nothing, then I found this question: Spring Boot War deployed to Tomcat which led me to these docs: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file and now It's starting the Spring boot app and the banner is displaying in my log file.

There are no errors however, and I'm wondering why I'm getting the 404.

There are messages in the log from Spring Security indicating that there's no controls around validate, so it seems to be getting the request, but not going anywhere with it.

Also, saw: Spring Boot Controller 404 and made sure that my controller is in a package beneath my Application class.

And I have an integration test in place that runs through the entire stack, so I'm confident that the Spring stuff is at least coded correctly.

Community
  • 1
  • 1
Thom
  • 14,013
  • 25
  • 105
  • 185
  • Is there a strong reason not to use the embedded container? Not having to deal with configuring the external container is one of Boot's major advantages. – chrylis -cautiouslyoptimistic- Aug 15 '16 at 18:08
  • @chrylis Not strong, no. It just seemed like a good idea to have all my test instances running under one tomcat on my test server. The alternative is to swap out the port numbers for test with several tomcat instances running on my test server, which is an older, limited, box. – Thom Aug 15 '16 at 18:10
  • Remember that you can set the port to 0 to randomize it. – chrylis -cautiouslyoptimistic- Aug 15 '16 at 18:12
  • @chrylis Then how do you test externally if you don't know what the port number is? – Thom Aug 15 '16 at 18:12
  • It prints the port on startup. If you're talking about using an external automated harness, then you'd generate a random port and set it as an environment variable (this is how it work on something like Cloud Foundry or Heroku). – chrylis -cautiouslyoptimistic- Aug 15 '16 at 18:14

3 Answers3

1

i have faced with the same issue.add your controller package name in the main class as mentioned below.

@SpringBootApplication(scanBasePackages={"com.design.order.controller"}

It resolved for me.

Guru Prasad
  • 70
  • 1
  • 3
-1

Can you check the war name. I tried the same sample that you have posted above and is working fine. Below is what I tried,

@Controller
public class MyController {

    @RequestMapping(value = "/validate", method= RequestMethod.GET)
    @ResponseBody
    public String validate( @RequestParam("userkey") String userkey) {
        System.out.println("in controller..");
        return "";
    }

}

pom.xml

<groupId>com.org.name</groupId>
    <artifactId>theta-server</artifactId>
    <version>0.1.0</version>
    <packaging>war</packaging>`

url

 http://localhost:8080/theta-server-0.1.0/validate?userkey=testkey
BSM
  • 173
  • 3
  • 13
-1

Try adding this below @Controller

@RequestMapping(value = "/theta-server")
Minh Duy
  • 127
  • 5