Java Spring控制器未获得扫描
控制器和项目结构: 我是春天发展的新手。我正在开发一个web应用程序。有一些jsp页面需要显示一些图像,因此我在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中删除上述条目,我的控制器将无法正确检测到。但是在删除图像后,找不到我缺少的
springservlet.xml
中创建了一个资源条目,如下所示:
<mvc:resources mapping="/schedules/**" location="/schedules/" />
但当我在添加这个条目时,我的控制器类停止了扫描,而我的动作在404中没有检测到。但如果我从xml中删除上述条目,我的控制器将无法正确检测到。但是在删除图像后,找不到我缺少的URL
<context:component-scan base-package="com.spring" />
xmlns:mvc=”http://www.springframework.org/schema/mvc“
在Spring servlet上下文xml配置中
标记是在Spring3.0.4中引入的,因此您至少需要该版本的Spring和xsd
是否为该文件夹下的所有内容谢谢大家的支持。问题解决了。实际上,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、控制器类(当前图片未提供关于类上使用的注释的任何线索)、资源路径图片