Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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 GET没有映射_Java_Spring - Fatal编程技术网

Java GET没有映射

Java GET没有映射,java,spring,Java,Spring,我通常使用xml配置,但现在只想使用java配置,但我的代码有点问题,我不知道要更改什么,因为一切似乎都很好 在glass fish上运行spring应用程序后,我遇到此错误: [glassfish 5.0][WARNING][[org.springframework.web.servlet.PageNotFound][tid:_ThreadID=30 _ThreadName=http-listener-1(2)][timeMillis:1619543716623][levelValue:900

我通常使用xml配置,但现在只想使用java配置,但我的代码有点问题,我不知道要更改什么,因为一切似乎都很好

在glass fish上运行spring应用程序后,我遇到此错误:

[glassfish 5.0][WARNING][[org.springframework.web.servlet.PageNotFound][tid:_ThreadID=30 _ThreadName=http-listener-1(2)][timeMillis:1619543716623][levelValue:900][[GET/spring\u project-1.0-SNAPSHOT/home/showHome/]无映射。

这是我的
控制器:

    @Controller
    @RequestMapping("/home")
    public class HomeController {
    
        @RequestMapping("/showHome")
        public String showHome() {
    
            return "home";
        }
    }
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.config")
public class AppConfig {

    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/view/");
        viewResolver.setSuffix(".jsp");

        return viewResolver;
    }
    public class AppIntializer  implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext container) {
        // Create the 'root' Spring application context
        AnnotationConfigWebApplicationContext rootContext =
                new AnnotationConfigWebApplicationContext();
        rootContext.register(AppConfig.class);

        // Manage the lifecycle of the root application context
        container.addListener(new ContextLoaderListener(rootContext));

        // Create the dispatcher servlet's Spring application context
        AnnotationConfigWebApplicationContext dispatcherContext =
                new AnnotationConfigWebApplicationContext();
        dispatcherContext.register(AppConfig.class);

        // Register and map the dispatcher servlet
        ServletRegistration.Dynamic dispatcher =
                container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");
    }

}
我的
视图解析器:

    @Controller
    @RequestMapping("/home")
    public class HomeController {
    
        @RequestMapping("/showHome")
        public String showHome() {
    
            return "home";
        }
    }
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.config")
public class AppConfig {

    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/view/");
        viewResolver.setSuffix(".jsp");

        return viewResolver;
    }
    public class AppIntializer  implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext container) {
        // Create the 'root' Spring application context
        AnnotationConfigWebApplicationContext rootContext =
                new AnnotationConfigWebApplicationContext();
        rootContext.register(AppConfig.class);

        // Manage the lifecycle of the root application context
        container.addListener(new ContextLoaderListener(rootContext));

        // Create the dispatcher servlet's Spring application context
        AnnotationConfigWebApplicationContext dispatcherContext =
                new AnnotationConfigWebApplicationContext();
        dispatcherContext.register(AppConfig.class);

        // Register and map the dispatcher servlet
        ServletRegistration.Dynamic dispatcher =
                container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");
    }

}
}

WebAppInitializer:

    @Controller
    @RequestMapping("/home")
    public class HomeController {
    
        @RequestMapping("/showHome")
        public String showHome() {
    
            return "home";
        }
    }
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.config")
public class AppConfig {

    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/view/");
        viewResolver.setSuffix(".jsp");

        return viewResolver;
    }
    public class AppIntializer  implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext container) {
        // Create the 'root' Spring application context
        AnnotationConfigWebApplicationContext rootContext =
                new AnnotationConfigWebApplicationContext();
        rootContext.register(AppConfig.class);

        // Manage the lifecycle of the root application context
        container.addListener(new ContextLoaderListener(rootContext));

        // Create the dispatcher servlet's Spring application context
        AnnotationConfigWebApplicationContext dispatcherContext =
                new AnnotationConfigWebApplicationContext();
        dispatcherContext.register(AppConfig.class);

        // Register and map the dispatcher servlet
        ServletRegistration.Dynamic dispatcher =
                container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");
    }

}

您需要在此行中指定HTTP方法

@RequestMapping("/showHome")
或者只是使用

@GetMapping
此外,请阅读下面的页面,它可能会很有用


从错误中可以看出,您正在尝试访问
GET/spring\u project-1.0-SNAPSHOT/home/showHome/
。尝试检查您正在访问的路径,我认为它应该是
/home/showHome/
仍然不起作用。当我使用
web.xml
/home/showHome/
!=<代码>/home/showHome