springmvcspring配置文件怎么写写

温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
&servlet-name&Demo2&/servlet-name&
&servlet-class&org.springframework.web.servlet.DispatcherServlet&/servlet-class&
&init-param&
&param-name&contextConfigLocation&/param-name&
&param-value&/WEB-INF/conf/applicationContext.xml&/param-value&
&/init-param&
&load-on-startup&1&/load-on-startup& &/servlet& 参考资料;/question/.html,那么context-param是不是可以不要设置呢,那也不行,会提示org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]但我设置的路径是/WEB-INF/conf下而不是/WEB-INF啊,只能猜想spring的默认路径是WEB-INF下,applicationContext或包含&servlet-name&-servlet.xml的配置文件,如果要使用其它路径,只能在servlet-name增加init-param配置了。
阅读(5183)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:' spring mvc项目配置文件修改默认路径方法',
blogAbstract:'IOException parsing XML document from ServletContext resource java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/Demo2-servlet.xml]',
blogTag:'could,not,open,servl',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:2,
publishTime:9,
permalink:'blog/static/',
commentCount:1,
mainCommentCount:1,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}博客访问: 1533090
博文数量: 506
博客积分: 7081
博客等级: 少将
技术积分: 5334
注册时间:
IT168企业级官微
微信号:IT168qiye
系统架构师大会
微信号:SACC2013
分类: Java
当我们在web.xml 中做如下配置的时候,DispatcherServlet 将会拦截所有的请求,包括对静态资源的请求(*.css,*.jpg,*.js....),这时候,如果我们没有相应的做一些配置上的调整的话,客户端将会出现404错误。为了解决这个问题,我们可以通过3种方式的配置来解决。
dispatcherServlet
1. 在web.xml中加入如下配置,使得容器的默认servlet来响应对静态资源的请求,根据请求资源的类型,调整mapping的配置。
&要写在DispatcherServlet的前面, 让defaultServlet先拦截,这个就不会进入Spring了,我想性能是最好的吧。
这样的配置性能应该是最高的,容器直接响应了客户端的请求,不需要再通过SpringMVC的框架了,缺点是,你的静态资源不能放在WEB-INF目录下了,必须和它处于同一级别。
&对于不同的web 容器,默认的servlet名字有所区别:
Tomcat, Jetty, JBoss, and GlassFish& 默认 Servlet的名字 -- "default"
Google App Engine 默认 Servlet的名字 -- "_ah_default"
Resin 默认 Servlet的名字 -- "resin-file"
WebLogic 默认 Servlet的名字& -- "FileServlet"
WebSphere& 默认 Servlet的名字 -- "SimpleFileServlet"&
2. 在spring mvc 的配置文件中加入如下一行:
& &优点:通过这一行的配置,框架中的ResourceHttpRequestHandler会帮你完成对静态资源的查找。缺点:同样不能访问位于 WEB-INF 下的资源
3.在spring mvc 配置中 通过
来指定对静态资源的映射,例如:
在这里我们可以看到,我们能把静态资源放在WEB-INF下。框架也是通过ResourceHttpRequestHandler来最终找到我们请求的资源的。
阅读(2706) | 评论(0) | 转发(0) |
相关热门文章
给主人留下些什么吧!~~
请登录后评论。<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&Spring MVC项目中通常会有二个配置文件,sprng-servlet.xml和applicationContext.xml二个配置文件,通常会出现以下几个配置
  1.&&context:annotation-config /&
  它的作用是隐式地向&Spring&容器注册 &AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、PersistenceAnnotationBeanPostProcessor、RequiredAnnotationBeanPostProcessor 这4个BeanPostProcessor。其作用是如果你想在程序中使用注解,就必须先注册该注解对应的类,如下图所示:
CommonAnnotationBeanPostProcessor
@Resource&、@PostConstruct、@PreDestroy
PersistenceAnnotationBeanPostProcessor的Bean
@PersistenceContext
AutowiredAnnotationBeanPostProcessor Bean
@Autowired
RequiredAnnotationBeanPostProcessor
  当然也可以自己进行注册:
&bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor "/&
&bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/&
  2.&&context:component-scan base-package="com.*" &
& & &&context:component-scan/& 配置项不但启用了对类包进行扫描以实施注释驱动 Bean 定义的功能,同时还启用了注释驱动自动注入的功能(即还隐式地在内部注册了 AutowiredAnnotationBeanPostProcessor 和 CommonAnnotationBeanPostProcessor),因此当使用 &context:component-scan/& 后,就可以将 &context:annotation-config/& 移除了。
& & &在这里有一个比较有意思的问题,就是扫描是否需要在二个配置文件都配置一遍,我做了这么几种测试:
  (1)只在applicationContext.xml中配置如下
&context:component-scan base-package="com.login" /&
& & &扫描到有@RestController、@Controller、@Compoment、@Repository等注解的类,则把这些类注册为Bean。  
& & &启动正常,但是任何请求都不会被拦截,简而言之就是@Controller失效
  (2)只在spring-servlet.xml中配置上述配置
  启动正常,请求也正常,但是事物失效,也就是不能进行回滚
  (3)在applicationContext.xml和spring-servlet.xml中都配置上述信息
  启动正常,请求正常,也是事物失效,不能进行回滚
  (4)在applicationContext.xml中配置如下
&context:component-scan base-package="com.login" /&
  在spring-servlet.xml中配置如下
&context:component-scan base-package="com.sohu.login.web" /&
  此时启动正常,请求正常,事物也正常了。
  结论:在spring-servlet.xml中只需要扫描所有带@Controller注解的类,在applicationContext中可以扫描所有其他带有注解的类(也可以过滤掉带@Controller注解的类)。
  & & &&http://blog.csdn.net/gladmustang/article/details/
  3.&&mvc:annotation-driven&/&
  它会自动注册RequestMappingHandlerMapping&与RequestMappingHandlerAdapter ( 3.1 以后DefaultAnnotationHandlerMapping 和AnnotationMethodHandlerAdapter已经可以不用了)
/yangzhilong/p/3725849.html
/questions//why-is-my-spring-autowired-field-null
官方文档:&http://docs.spring.io/spring/docs/4.2.2.BUILD-SNAPSHOT/spring-framework-reference/htmlsingle/#beans-autowired-annotation
区别:&http://my.oschina.net/HeliosFly/blog/205343
###################################################################################################
spring中classpath和classpath*的配置区别
我们以spring中加载properties资源文件为例讲解,目录结构大致如下:
│&&├─filters
│&&├─java
│&&│&&└─com
│&&│&&&&&&└─micmiu
│&&│&&&&&&&&&&├─demoweb
│&&│&&&&&&&&&&│&&│ ....
│&&│&&&&&&&&&&│&&│
│&&│&&&&&&&&&&│&&└─utils
│&&│&&&&&&&&&&│
│&&│&&&&&&&&&&└─modules
│&&├─resources
│&&│&&│&&application.properties
│&&│&&│&&applicationContext-shiro.xml
│&&│&&│&&applicationContext.xml
│&&│&&│&&hibernate.cfg.xml
│&&│&&│&&log4j.properties
│&&│&&│&&spring-mvc.xml
│&&│&&│&&spring-view.xml
│&&└─webapp
│&&&&&&│
│&&&&&&└─WEB-INF
&&&&├─java
&&&&│&&└─com
&&&&│&&&&&&└─micmiu
&&&&│&&&&&&&&&&├─demoweb
&&&&│&&&&&&&&&&│&&&&&&TestOther.java
&&&&└─resources
&&&&&&&&&&&&application.properties
同时 在该项目的lib中添加一个测试的micmiu-test.jar包,jar包中的文件结构如下:
micmiu-test.jar
│&&application.properties
│&&└─micmiu
│&&&&&&└─test
│&&&&&&&&&&&&&&application.properties
│&&&&&&&&&&&&&&RunApp.class
└─META-INF
&&&&&&&&MANIFEST.MF
从准备的测试环境中我们可以看到在不同目录下的四个同名的application.properties资源文件。
[二]、测试代码:TestClassPath.java&&
1 package com.micmiu.
3 import org.springframework.context.ApplicationC
4 import org.springframework.context.support.ClassPathXmlApplicationC
6 public class TestClassPath {
7   public static void main(String[] args) {
8     ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:/applicationContext.xml");
9       System.out.println(ctx.getClassLoader().getResource("").getPath());
[三]、测试结果
spring配置文件:applicationContext.xml 中两种不同的properties文件加载配置:
第一种配置:classpath:
&context:property-placeholder&ignore-unresolvable="true"&location="classpath:/application.properties"&/&
&Loading&properties&file&from&class&path&resource&[application.properties]
第二种配置:&classpath*:
&&context:property-placeholder&ignore-unresolvable="true"&&location="classpath*:/application.properties"
Loading&properties&file&from&URL&[file:/D:/workspace_sun/framework-dev/micmiu-demoweb/target/test-classes/application.properties]
Loading&properties&file&from&URL&[file:/D:/workspace_sun/framework-dev/micmiu-demoweb/target/classes/application.properties]
Loading&properties&file&from&URL&[jar:file:/D:/micmiu-test.jar!/application.properties]
由此日志信息可知:
同名资源存在时,classpath: 只从第一个符合条件的classpath中加载资源,而classpath*: 会从所有的classpath中加载符合条件的资源
classpath*:需要遍历所有的classpath,效率肯定比不上classpath,因此在项目设计的初期就尽量规划好资源文件所在的路径,避免使用classpath*来加载
阅读(...) 评论() &}

我要回帖

更多关于 springmvc配置文件头 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信