Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring-找不到URI为的HTTP请求的映射_Java_Spring_Post_Methods - Fatal编程技术网

Java Spring-找不到URI为的HTTP请求的映射

Java Spring-找不到URI为的HTTP请求的映射,java,spring,post,methods,Java,Spring,Post,Methods,我正在编写一个Spring服务器的代码,我正在使用改型来进行api调用 我有改装客户端的下一个界面: import retrofit.http.Body; import retrofit.http.GET; import retrofit.http.POST; public interface AuthSvcApi { public static final String AUTHENTICATION_PATH = "/authToken"; @POST(AUTHENTIC

我正在编写一个Spring服务器的代码,我正在使用改型来进行api调用

我有改装客户端的下一个界面:

import retrofit.http.Body;
import retrofit.http.GET;
import retrofit.http.POST;

public interface AuthSvcApi {

    public static final String AUTHENTICATION_PATH = "/authToken";

    @POST(AUTHENTICATION_PATH)
    public boolean loginUser(@Body String accessToken);
}
那么我的控制器是:

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.purposes.client.AuthSvcApi;

@Controller
public class AuthSvc{

    @RequestMapping(value=AuthSvcApi.AUTHENTICATION_PATH, method = RequestMethod.POST)
    public @ResponseBody boolean loginUser(@RequestBody String accessToken) {
        CheckAccessToken checkAccessToken = new CheckFacebookAccessToken();
        checkAccessToken.checkToken(accessToken);
        return false;
    }
}
该方法尚未完成,但应该可以工作。应用程序类别为:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;


//Tell Spring to automatically inject any dependencies that are marked in
//our classes with @Autowired
@EnableAutoConfiguration
//Tell Spring to turn on WebMVC (e.g., it should enable the DispatcherServlet
//so that requests can be routed to our Controllers)
@EnableWebMvc
//Tell Spring to go and scan our controller package (and all sub packages) to
//find any Controllers or other components that are part of our applciation.
//Any class in this package that is annotated with @Controller is going to be
//automatically discovered and connected to the DispatcherServlet.
@ComponentScan
//Tell Spring that this object represents a Configuration for the
//application
@Configuration
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
我不知道这为什么不起作用,但我快发疯了,因为我的回答是:

No mapping found for HTTP request with URI [/authToken] in DispatcherServlet with name 'dispatcherServlet'

看起来您需要包括AuthSvcApi.AUTHENTICATION\u路径 关于这一行:

.setEndpointSERVER.build

像这样:
.setEndpointSERVER+AuthSvcApi.AUTHENTICATION\u PATH.build

我找到了解决方案,问题是注释@ComponentScan没有找到控制器所在的包。我解决了向注释指示控制器所在的包的问题


@ComponentScanbasePackages={com.purposes.controllers}

我认为这不是错误,因为端点是服务器的名称。无论如何,我会证明这一点;这不是问题所在,问题是我需要在应用程序类中使用@EnableWebMvc注释。现在,我遇到了另一个问题,我在名为“DispatcherServlet”的DispatcherServlet中收到了一条消息,没有为URI为[/authToken]的HTTP请求找到映射,因为DispatcherServlet没有映射我的url。