Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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控制器未获得扫描_Java_Spring_Spring Mvc_Spring Boot - Fatal编程技术网

Java Spring控制器未获得扫描

Java Spring控制器未获得扫描,java,spring,spring-mvc,spring-boot,Java,Spring,Spring Mvc,Spring Boot,控制器和项目结构: 我是春天发展的新手。我正在开发一个web应用程序。有一些jsp页面需要显示一些图像,因此我在springservlet.xml中创建了一个资源条目,如下所示: <mvc:resources mapping="/schedules/**" location="/schedules/" /> 但当我在添加这个条目时,我的控制器类停止了扫描,而我的动作在404中没有检测到。但如果我从xml中删除上述条目,我的控制器将无法正确检测到。但是在删除图像后,找不到我缺少的

控制器和项目结构:

我是春天发展的新手。我正在开发一个web应用程序。有一些jsp页面需要显示一些图像,因此我在
springservlet.xml
中创建了一个资源条目,如下所示:

<mvc:resources mapping="/schedules/**" location="/schedules/" />

但当我在添加这个条目时,我的控制器类停止了扫描,而我的动作在404中没有检测到。但如果我从xml中删除上述条目,我的控制器将无法正确检测到。但是在删除图像后,找不到我缺少的URL

<context:component-scan base-package="com.spring" />

  • 检查mvc XML命名空间是否位于
    xmlns:mvc=”http://www.springframework.org/schema/mvc“
    在Spring servlet上下文xml配置中
  • 标记是在Spring3.0.4中引入的,因此您至少需要该版本的Spring和xsd
  • 我的建议是使用最新的spring版本
  • 在配置文件中添加
  • 检查资源文件夹行
    是否为该文件夹下的所有内容

  • 谢谢大家的支持。问题解决了。实际上,xml标记应该声明一个层次结构

    下面的代码适合我

    <context:component-scan base-package="com.spring" />
    <mvc:resources mapping="/schedules/**" location="/schedules/" /> 
    
    <mvc:default-servlet-handler />
    <mvc:annotation-driven/>
    
    
    
    现在我的xml是这样的

    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans     
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    
    
        <context:component-scan base-package="com.spring" />
        <mvc:resources mapping="/schedules/**" location="/schedules/" /> 
    
        <mvc:default-servlet-handler />
        <mvc:annotation-driven/>
    
        <bean id="multipartResolver"
            class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
    
        <!-- Register the welcome.properties -->
        <bean id="messageSource"
            class="org.springframework.context.support.ResourceBundleMessageSource">
            <property name="basename" value="ApplicationResources" />
        </bean>
    
        <bean id="viewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix">
                <value>/WEB-INF/</value>
            </property>
            <property name="suffix">
                <value>.jsp</value>
            </property>
        </bean>
    
    
    
    </beans>  
    
    
    /WEB-INF/
    .jsp
    
    基本包应该指向您的包而不是spring实际上我的包名是spring显示您的控制器代码和项目结构您可以试试这个:@ScaryWombat这是我的spring confi我也试过了。但是没有任何区别。让我把spring也换成最新版本。根据时间表,一些自动生成的图像出现了。无其他内容请共享您的web.xml、控制器类(当前图片未提供关于类上使用的注释的任何线索)、资源路径图片