简体   繁体   English

无法进入我的Spring Boot Controller方法

[英]Can't get to my spring boot controller methods

It's been a while and I'm updating my skills for Spring and Spring boot. 已经有一段时间了,我正在更新Spring和Spring Boot的技能。 To that end, I'm building a web application. 为此,我正在构建一个Web应用程序。 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: 部署似乎进展顺利,战争被命名为theta-server,并进入了tomcat / webapps,因此,我进入浏览器并输入:

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

and I get a 404. 我得到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. 最初我什么也没有,然后我发现了这个问题: Spring Boot War部署到Tomcat ,这使我想到了这些文档: http : //docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-创建一个可部署的战争文件 ,现在它正在启动Spring Boot应用程序,并且横幅显示在我的日志文件中。

There are no errors however, and I'm wondering why I'm getting the 404. 但是没有错误,我想知道为什么要得到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. Spring Security的日志中有消息表明,validate周围没有控件,因此它似乎正在获取请求,但并没有解决任何问题。

Also, saw: Spring Boot Controller 404 and made sure that my controller is in a package beneath my Application class. 此外,还看到了: Spring Boot Controller 404 ,并确保我的控制器位于Application类下面的包中。

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. 而且我已经在整个堆栈中进行了集成测试,因此我相信Spring的东西至少可以正确编码。

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"} @SpringBootApplication(scanBasePackages = {“ com.design.order.controller”}

It resolved for me. 它为我解决了。

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 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

尝试在@Controller下面添加它

@RequestMapping(value = "/theta-server")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM