spring-servlet.xml cannot reference <mvc:resources/> tag

 When using the <mvc:resources/> tag in spring-servlet.xml, it was found that it could not be referenced, and many solutions were found on the Internet without success. In the end, there was really no way to copy a copy of someone else's and use it. I compared and found the difference between the two files as follows:

<?xml version="1.0" encoding="UTF-8"?>    
<beans xmlns="http://www.springframework.org/schema/beans"   
    xmlns:context="http://www.springframework.org/schema/context"   
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xmlns:p="http://www.springframework.org/schema/p"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
    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.xsd  
    http://www.springframework.org/schema/mvc   
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">  

	<!-- scan controller package -->
	<!--<context:component-scan base-package="com.founder.controller" />-->
	
	<bean name="/test/hello" class="com.founder.controller.HelloworldController"></bean>
	
	<!-- Multi-method parser-->
	<bean name="paramMethodResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
		<property name="paramName" value="action"></property>	
	</bean>
	
	<bean name="/test/multi" class="com.founder.controller.MultiController">
		<property name="methodNameResolver">
			<ref bean="paramMethodResolver"></ref>
		</property>
	</bean>
	
	<bean name="/test/static" class="com.founder.controller.StaticController">
		<property name="methodNameResolver">
			<ref bean="paramMethodResolver"></ref>
		</property>
	</bean>
	
	 <!-- Static resource access (do not intercept access to things in this directory) -->  
    <mvc:resources location="/img/"  mapping="/img/**" />
	
	<!-- View resolver -->
	<bean id="viewResolver"
		  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>

</beans>

 

Not available spring-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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">

	<!-- scan controller package -->
	<!--<context:component-scan base-package="com.founder.controller" />-->
	
	<bean name="/test/hello" class="com.founder.controller.HelloworldController"></bean>
	
	<!-- Multi-method parser-->
	<bean name="paramMethodResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
		<property name="paramName" value="action"></property>	
	</bean>
	
	<bean name="/test/multi" class="com.founder.controller.MultiController">
		<property name="methodNameResolver">
			<ref bean="paramMethodResolver"></ref>
		</property>
	</bean>
	
	<!-- View resolver -->
	<bean id="viewResolver"
		  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>

</beans>

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326443929&siteId=291194637