我使用spring mvc创建一个rest Web服务。但是,我总是得到404.我不知道哪里出错了。
这是我的初始化程序:
//gestures
let gesture_tap = UITapGestureRecognizer(target: self, action: #selector(ComponentDetailViewController.ctrl_tapped(_:event:)));
let gesture_pinch = UIPinchGestureRecognizer(target: self, action: #selector(ComponentDetailViewController.ctrl_pinched(_:event:)));
let gesture_swipe = UISwipeGestureRecognizer(target:self, action: #selector(ComponentDetailViewController.ctrl_swiped(_:event:)));
let gesture_longPress = UILongPressGestureRecognizer(target: self, action: #selector(ComponentDetailViewController.ctrl_longPressed(_:event:)));
let gesture_rotate = UIRotationGestureRecognizer(target:self,action: #selector(ComponentDetailViewController.ctrl_rotated(_:event:)));
let gesture_pan = UIPanGestureRecognizer(target:self, action: #selector(ComponentDetailViewController.ctrl_panned(_:event:)));
let ctrl = component?.control;
ctrl!.addGestureRecognizer(gesture_tap);
ctrl!.addGestureRecognizer(gesture_pinch);
ctrl!.addGestureRecognizer(gesture_swipe);
ctrl!.addGestureRecognizer(gesture_longPress);
ctrl!.addGestureRecognizer(gesture_rotate);
ctrl!.addGestureRecognizer(gesture_pan);
gesture_tap.delegate = self;
gesture_pinch.delegate = self;
gesture_swipe.delegate = self;
gesture_longPress.delegate = self;
gesture_rotate.delegate = self;
gesture_pan.delegate = self;
component?.control = ctrl as? UIView;
//component?.control!.userInteractionEnabled = true;
//component?.control!.addGestureRecognizer(tap);
viewDisplayComponent.addSubview((component?.control)! as! UIView);
}
//Gesture methods
func ctrl_tapped(ctrl: AnyObject, event:UIEvent){
setMessage("TO_tapped");
}
func ctrl_pinched(ctrl: AnyObject, event:UIEvent){
setMessage("TO_pinchedWithArgs")
}
func ctrl_swiped(ctrl: AnyObject, event:UIEvent){
setMessage("TO_swipedWithArgs");
}
func ctrl_longPressed(ctrl: AnyObject, event:UIEvent){
setMessage("TO_longPressedWithArgs");
}
func ctrl_rotated(ctrl: AnyObject, event:UIEvent){
//logTextView.text += "Rotated";
}
func ctrl_panned(ctrl: AnyObject, event:UIEvent){
setMessage("TO_pannedWithArgs");
}
这是我的Webconfig:
public class Initializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
// TODO Auto-generated method stub
return new Class<?>[] { RootConfig.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
// TODO Auto-generated method stub
return new Class<?>[] { WebConfig.class };
}
@Override
protected String[] getServletMappings() {
// TODO Auto-generated method stub
return new String[] { "/" };
}
}
这是我的休息服务器文件:
@Configuration
@EnableWebMvc
@ComponentScan("com.jh.dummy.web")
public class WebConfig extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResovler = new InternalResourceViewResolver();
viewResovler.setPrefix("/");
viewResovler.setSuffix(".html");
viewResovler.setExposeContextBeansAsAttributes(true);
return viewResovler;
}
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
以下是请求:
当我使用卷曲测试时,我总是得到404.我找不到哪里出错了。有什么想法吗?
答案 0 :(得分:0)
我解决了这个问题。事实证明我需要在url中添加/ dummy /。因此,网址将是&#34; localhost:8080 / dummy / v1 / position / v1&#34;。但在我的其他项目案例中,我不需要将项目名称添加到虚拟项目中。这次我仍然不知道为什么我需要这样做。当我发现时,我会告诉你那个人。