`

spring-servlet.xml 无法引用<mvc:resources />标签

 
阅读更多

 在spring-servlet.xml 中使用<mvc:resources/> 标签的时候,发现无法引用,在网上查到了很多解决办法都无功而返。 最后实在没有办法就copy了一份别人的拿来用。 我对比了一下,发现两个文件的区别如下:

<?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">  

	<!-- 扫描控制器包-->
	<!--<context:component-scan base-package="com.founder.controller" />-->
	
	<bean name="/test/hello" class="com.founder.controller.HelloworldController"></bean>
	
	<!-- 多方法解析器 -->
	<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>
	
	 <!-- 静态资源访问(不拦截此目录下的东西的访问) -->  
    <mvc:resources location="/img/"  mapping="/img/**" />
	
	<!-- 视图解析器 -->
	<bean id="viewResolver" 
		  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>

</beans>

 

不可用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">

	<!-- 扫描控制器包-->
	<!--<context:component-scan base-package="com.founder.controller" />-->
	
	<bean name="/test/hello" class="com.founder.controller.HelloworldController"></bean>
	
	<!-- 多方法解析器 -->
	<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 id="viewResolver" 
		  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>

</beans>

 

 

分享到:
评论

相关推荐

    基于MyEclipse搭建maven+springmvc整合图文教程(含源码0

    &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/dispatcher-servlet.xml&lt;/...

    Spring3中配置DBCP,C3P0,Proxool,Bonecp数据源

    &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt; &lt;mvc:default-servlet-handler /&gt; &lt;aop:config proxy-target-class="true"/&gt; &lt;tx:annotation-driven transaction-manager="txManager"/&gt; &...

    t淘淘商城项目 商城项目 视频和源码教程 详细

    &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt; &lt;version&gt;${spring.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt; &lt;version&gt;${...

    SSM框架整合

    &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt; &lt;/dependency&gt; &lt;!-- Jackson Json处理工具包(非必须) --&gt; &lt;dependency&gt; &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt; &lt;artifactId&gt;jackson-databind&lt;/...

    SpringMVC+Hibernate全注解整合

    &lt;bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /&gt; ...

    spring-boot-reference.pdf

    Auto-configured Spring REST Docs Tests with Mock MVC Auto-configured Spring REST Docs Tests with REST Assured 43.3.20. User Configuration and Slicing 43.3.21. Using Spock to Test Spring Boot ...

    单点登录源码

    SpringMVC | MVC框架 | [http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc](http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc) ...

    springmybatis

    查询出列表,也就是返回list, 在我们这个例子中也就是 List&lt;User&gt; , 这种方式返回数据,需要在User.xml 里面配置返回的类型 resultMap, 注意不是 resultType, 而这个resultMap 所对应的应该是我们自己配置的 ...

    开发用jar包合集

    spring-webmvc-5.0.6.RELEASE-sources.jar spring-webmvc-5.0.6.RELEASE.jar spring-websocket-5.0.6.RELEASE-javadoc.jar spring-websocket-5.0.6.RELEASE-sources.jar spring-websocket-5.0.6.RELEASE.jar ...

    dubbo、dubbox编译所需jar包

    spring-webmvc-3.2.16.RELEASE.jar surefire-api-2.17.jar surefire-booter-2.17.jar surefire-grouper-2.17.jar surefire-junit4-2.12.4.jar surefire-junit4-2.17.jar surefire-report-parser-2.17.jar tomcat-...

    spring-framework-reference-4.1.2

    3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................

    spring-framework-reference4.1.4

    3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................

    Spring中文帮助文档

    9.5.5. &lt;tx:advice/&gt; 有关的设置 9.5.6. 使用 @Transactional 9.5.7. 事务传播 9.5.8. 通知事务操作 9.5.9. 结合AspectJ使用 @Transactional 9.6. 编程式事务管理 9.6.1. 使用TransactionTemplate 9.6.2. ...

    Spring API

    9.5.5. &lt;tx:advice/&gt; 有关的设置 9.5.6. 使用 @Transactional 9.5.7. 事务传播 9.5.8. 通知事务操作 9.5.9. 结合AspectJ使用 @Transactional 9.6. 编程式事务管理 9.6.1. 使用TransactionTemplate 9.6.2. ...

    springboot学习思维笔记.xmind

    Spring MVC的常用注解 @Controller @RequestMapping @ResponseBody @RequestBody @PathVariable @RestController Spring MVC的基本配置 静态资源映射 拦截器配置 @ControllerAdivce ...

    基于框架的Web开发-第一个springMVC的例子.doc

    和mvc同一层次的resources文件夹,里面放系统配置文件applicationContext.xml顶层包mvc,下面分三个子包domain,service和web,mvc.web包里放控制器类WEB-INF文件夹下放置web.xml文件和mySpring-servlet.xml文件Web...

    Maven权威指南 很精典的学习教程,比ANT更好用

    添加一个简单的Servlet 5.6. 添加J2EE依赖 5.7. 小结 6. 一个多模块项目 6.1. 简介 6.1.1. 下载本章样例 6.2. simple-parent 项目 6.3. simple-weather 模块 6.4. simple-webapp 模块 6.5. 构建这个多...

    java8集合源码分析-thinking-in-spring:小马哥极客时间Spring编程思想示例项目

    资源管理(Resources) 国际化(i18n) 校验(Validation) 数据绑定(Data Binding) 类型装换(Type Conversion) Spring 表达式(Spring Express Language) 面向切面编程(AOP) 数据存储(Data Access) JDBC 事务抽象...

    xmljava系统源码-myEmail:自己创建的小型邮件收发系统

    pom.xml中有该系统需要依赖的包,tomcat中的servlet-api包需要自己添加。 src中的java为java代码,为本系统后台代码。 src中的resources中文件为资源文件。 src中的webapp下为前端相关代码。 成果展示 登录界面 登录...

Global site tag (gtag.js) - Google Analytics