我正在编写Spring服务器,并使用Retrofit进行api调用。Spring - 未找到具有URI的HTTP请求的映射
我对改造客户端的下一个界面:
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'
我认为这是没有错误的,因为终点是服务器的名称。我会证明,无论如何;) – abemart 2014-09-07 17:33:19
这不是问题,问题是我需要Application类中的@EnableWebMvc注释。现在,我还有其他问题,我收到消息'DispatcherServlet'中名为'dispatcherServlet'的未使用URI [/ authToken]为HTTP请求找到映射,因为dispatcherServlet没有映射我的URL。 – abemart 2014-09-08 09:31:09