spring容器结合springspring mvc容器加载有什么用

为啥Spring和Spring MVC包扫描要分开? - labreeze - ITeye博客
最近在搭建新工程的时候发现有些Spring的配置不是很了解,比如Spring 配置里面明明配置了component-scan,为啥Spring MVC配置文件还需要配置一下,这样岂不是多此一举?由于以前基本是在现有的工程上直接开发或者别的工程的配置文件直接拷贝过来,所以也没太关注这个问题。出于好奇,谷歌了一下发现原来这个里面大有学问呢,详情请见下文。正常代码如下:
&!-- spring 配置文件--&
&context:component-scan base-package="com.xxx.xxx.account.front"&
&context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" /&
&/context:component-scan&
&!-- spring mvc --&
&context:component-scan base-package="com.xxx.xxx.account.front.web" use-default-filters="false"&
&context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" /&
&/context:component-scan&
public class TestService implements InitializingBean {
@Autowired
private PersonalAddressAjaxController personalAddressAjaxC
public void afterPropertiesSet() throws Exception {
System.out.println("--------------------------------");
原来Spring 是父容器, Spring MVC是子容器, 子容器可以访问父容器的bean,父容器不能访问子容器的bean。
具体参照:
测试一: Spring加载全部bean,MVC加载Controller
&!-- spring 配置文件--&
&context:component-scan base-package="com.xxx.xxx.account.front"&
&/context:component-scan&
&!-- spring mvc --&
&context:component-scan base-package="com.xxx.xxx.account.front.web" use-default-filters="false"&
&context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" /&
&/context:component-scan&
测试结果:TestService通过,界面显示正常。
原因:父容器加载了全部bean,所以Service 能访问到Controller。MVC容器默认查找当前容器,能查到有转发的Controller规则所以界面正常跳转。
测试二:Spring加载全部Bean,MVC容器啥也不加载
&!-- spring 配置文件--&
&context:component-scan base-package="com.xxx.xxx.account.front"&
&/context:component-scan&
&!-- spring mvc --&
测试结果:TestService通过,界面显示404。
原因:父容器加载了全部bean,所以Service 能访问到Controller。MVC容器默认查找当前容器的Controller,找不到所以界面出现404。
测试三:Spring加载所有除了Controller的bean,MVC只加载Controller
&!-- spring 配置文件--&
&context:component-scan base-package="com.xxx.xxx.account.front"&
&context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" /&
&/context:component-scan&
&!-- spring mvc --&
&context:component-scan base-package="com.xxx.xxx.account.front.web" use-default-filters="false"&
&context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" /&
&/context:component-scan&
测试结果:TestService初始化失败,如果注释掉该bean,界面正常。
原因:父容器不能访问子容器的bean。
测试四:Spring不加载bean,MVC加载所有的bean
&!-- spring 配置文件--&
&!-- spring mvc --&
&context:component-scan base-package="com.xxx.xxx.account.front.web" use-default-filters="true"&
&/context:component-scan&
测试结果:TestService通过,界面正常。
原因:因为所有的bean都在子容器中,也能查到当前容器中的Controller,所以没啥问题。
疑问一: 单例的bean在父子容器中存在一个实例还是两个实例?
答:初始化两次,Spring 容器先初始化bean,MVC容器再初始化bean,所以应该是两个bean。
疑问二:为啥不把所有bean 都在子容器中扫描?
答: 网上很多文章说子容器不支持AOP,其实这是不对的。因为正常会有AOP的相关配置都在Spring容器中配置,如果都迁移到MVC配置文件,则所有bean都在子容器中,相当于只有一个容器了,所以也就实现了AOP。缺点是不利于扩展。
浏览: 96886 次
起初觉得这些写博客都是大牛级,后面才发现不过是只字不漏的摘抄, ...
szq80140 写道@PostConstruct 也可以试了 ...
@PostConstruct 也可以
&&& inter interceptor
renzhengzhi 写道实际是因为Exception是Th ...spring和springmvc两个容器的组件注册
为项目添加了mybatis之后发现事务不能生效,项目使用了springmvc和spring
springmvc的配置如下 ,dispatcher-servlet.xml
&?xml version="1.0" encoding="UTF-8"?&
&beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"&
upload file --&
&beans:bean id="multipartResolver" class="org.springframework.monsMultipartResolver"&
&beans:property name="defaultEncoding" value="utf-8" /&
&beans:property name="maxUploadSize" value="" /&
&beans:property name="maxInMemorySize" value="40960" /&
&/beans:bean&
&!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --&
&beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&
&beans:property name="prefix" value="/WEB-INF/views/" /&
&beans:property name="suffix" value=".jsp" /&
&/beans:bean&
&/beans:beans&
有关拦截器和包扫描以及注册@controller的配置都是放到了spring的配置文件
如下spring-context.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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"&
&aop:aspectj-autoproxy /&
&context:component-scan base-package="com.xyz" /&
&bean class="com.xyz.util.base.SpringContextHolder"
lazy-init="false" /&
&!-- spring的属性加载器,加载properties文件中的属性 --&
&bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&
&property name="locations"&
&value&classpath:main.properties&/value&
&/property&
&property name="fileEncoding" value="utf-8" /&
spring-framework.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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"&
&aop:aspectj-autoproxy /&
&mvc:annotation-driven&
&/mvc:annotation-driven&
&!-- 拦截器 --&
&mvc:interceptors&
&bean class="com.xyz.framework.FrameworkInterceptor"&&/bean&
&!-- 拦截指定url --&
&!-- &mvc:interceptor&
&mvc:mapping path="/home/do/*" /&
&bean class="com.xyz.framework.JsonInterceptor"&&/bean&
&/mvc:interceptor& --&
&/mvc:interceptors&
spring的配置文件是在web.xml种通过ContextLoaderListener指定contextConfigLocation来加载。
这样做,是不是把原本应该在springmvc管理的组件交给了spring来管理?
因为发现这样再整合mybatis事务就不生效了是不是需要把controller交给springmvc管理,service交给spring管理?
这样貌似不好吧,controller应该在mvc的配置里面扫描装载,否则上下文环境有一点点不一样,貌似会有一点点小问题。
还有,你的配置文件第三个应该和第二个合在一起,你再试试看Spring(42)
SpringMVC(39)
转自:/zyzcj/p/5286190.html
Spring和SpringMVC作为Bean管理容器和MVC层的默认框架,已被众多WEB应用采用,而实际使用时,由于有了强大的注解功能,很多基于XML的配置方式已经被替代,但是在实际项目中,同时配置Spring和SpringMVC时会出现一些奇怪的异常,比如Bean被多次加载,多次实例化,或者依赖注入时,Bean不能被自动注入,但是明明你已经将该Bean注册了的。找原因还是要看问题的根源,我们从容器说起。
在Spring整体框架的核心概念中,容器是核心思想,就是用来管理Bean的整个生命周期的,而在一个项目中,容器不一定只有一个,Spring中可以包括多个容器,而且容器有上下层关系,目前最常见的一种场景就是在一个项目中引入Spring和SpringMVC这两个框架,其实就是2个容器,Spring是根容器,SpringMVC是其子容器,并且在Spring根容器中对于SpringMVC容器中的Bean是不可见的,而在SpringMVC容器中对于Spring根容器中的Bean是可见的,也就是子容器可以看见父容器中的注册的Bean,反之就不行。理解这点很重要,因为这是一个规则,是Spring自己设定的,但是往下看,我们会发现有些地方它并不默认使用这个规则。
当我们使用注解时,对于Bean注册这个功能的实现就不需要在给每个Bean配置XML了,只要使用统一的如下配置即可。
&context:component-scan&base-package=“com.test&
根据Spring提供的参考手册,该配置的功能是扫描默认包下的所有的@Component注解,并且自动注册到容器中,同时也扫描@Controller,@Service,@Respository这三个注解,他们是继承自@Component。
除了以上我们使用的扫描配置,在项目中我们经常见到的就是&context:annotation-config/&这个配置,其实有了以上的配置,这个是可以省略掉的。
还有一个SpringMVC相关的是&mvc:annotation-driven&/&配置,经过验证,这个是必须要配置的,因为它是和@RequestMapping结合使用的,这里补充下SpringMVC框架相关的知识点。
HandlerMapping,是SpringMVC中用来处理Request请求URL到具体Controller的,其自身也分成很多种类;&
HandlerAdapter,是SpringMVC中用来处理具体请求映射到具体方法的,其自身也分很多种类;
@RequestMapping这个注解的主要目的就是对具体的Controller和方法进行注册,以方便HandlerMapping用来处理请求的映射。但是@RequestMapping需要结合&mvc:annotation-driven&/&使用才能生效。
好了,有了以上基础知识的铺垫,我们看下现在这样的一个使用场景中,Spring与SpringMVC的容器冲突的原因在那里!
Spring配置文件applicationContext.xml,SpringMVC配置文件applicationContext-MVC.xml,这样项目中就有2个容器了,配置方式A,如下:
applicationContext.xml中配置了&context:component-scan&base-package=“com.test& /&,负责所有需要注册的Bean的扫描工作,applicationContext-MVC.xml中配置&mvc:annotation-driven&/&,负责springMVC相关注解的使用,启动项目发现,springMVC失效,无法进行跳转,开启log的DEBUG级别进行调试,发现springMVC容器中的请求好像没有映射到具体controller中;
配置方式B,如下:
为了快速验证效果,将&context:component-scan&base-package=“com.test& /&扫描配置到applicationContext-MVC.xml中,重启后,验证成功,springMVC跳转有效。
要想查看具体原因,翻看源码,从springMVC的DispatcherServlet开始看,在一个请求进来之后,发生了什么?漫长的查看之后,找到原因,如下。
springMVC初始化时,会寻找所有当前容器中的所有@Controller注解的Bean,来确定其是否是一个handler,而当前容器springMVC中注册的Bean中并没有@Controller注解的,注意,上面提及的配置方式A,所有的@Controller配置的Bean都注册在Spring这个父容器中了,看代码。
protected&void&initHandlerMethods()&{
& &&if&(logger.isDebugEnabled())&{
& & & &&logger.debug(&Looking&for&request&mappings&in&application&context:&&&+&getApplicationContext());
& &&String[]&beanNames&=&(this.detectHandlerMethodsInAncestorContexts&?
& & & & & &&BeanFactoryUtils.beanNamesForTypeIncludingAncestors(getApplicationContext(),&Object.class)&:
& & & & & &&getApplicationContext().getBeanNamesForType(Object.class));
& &&for&(String&beanName&:&beanNames)&{
& & & &&if&(isHandler(getApplicationContext().getType(beanName))){
& & & & & &&detectHandlerMethods(beanName);
& &&handlerMethodsInitialized(getHandlerMethods());
在方法isHandler中会判断当前bean的注解是否是controller,代码如下:
protected&boolean&isHandler(Class&?&&beanType)&{
& &&return&AnnotationUtils.findAnnotation(beanType,&Controller.class)&!=&null;
在配置方式B中,springMVC容器中包括了所有的@Controller注解的Bean,所以自然就能找到了。
以上是原因,解决办法是什么?注意看initHandlerMethods()方法中,detectHandlerMethodsInAncestorContexts这个Switch,它主要控制从那里获取容器中的bean,是否包括父容器,默认是不包括的。所以解决办法是有的,即在springMVC的配置文件中配置HandlerMapping的detectHandlerMethodsInAncestorContexts属性为true即可(这里需要根据具体项目看使用的是哪种HandlerMapping),让其检测父容器的bean。如下:
&bean&class=&org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping&&
& &&&property&name=&detectHandlerMethodsInAncestorContexts&&
& & & &&&value&true&/value&
& &&&/property&
&&&&&/bean&
以上已经有了2种解决方案了,但在实际工程中,会包括很多配置,根据不同的业务模块来划分,所以我们一般思路是各负其责,明确边界,Spring根容器负责所有其他非controller的Bean的注册,而SpringMVC只负责controller相关的Bean的注册。第三种方案如下:
Spring容器配置,排除所有@controller的Bean
&context:component-scan&base-package=&com.fsnip.open&&
& &&&context:exclude-filter&type=&annotation&&expression=&org.springframework.stereotype.Controller&/&
&&&&&/context:component-scan&
SpringMVC容器配置,让其只包括@controller的Bean
&context:component-scan&base-package=&com.fsnip.open&&use-default-filters=&false&&
& &&&context:include-filter&type=&annotation&&expression=&org.springframework.stereotype.Controller&&/&
&&&&&/context:component-scan&
个人比较推荐第三种方案。引申一下,项目中使用事务的配置方案,也会在这种场景下失效,归根结底也是由于2个容器的可见性问题导致,可以结合具体问题按照上面的思路进行查找原因!
引用一下海涛的博客中的一张图。 原图地址/blog/1602617
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:428398次
积分:6843
积分:6843
排名:第3224名
原创:217篇
转载:284篇
译文:22篇
评论:59条
(9)(6)(9)(16)(17)(17)(8)(43)(77)(103)(14)(12)(58)(40)(26)(40)(30)Spring WebMVC List容器元素的Data Bind -
- ITeye博客
最近学习SpringMVC,做了一个小Demo, 发现一个问题:无法绑定command对象List Field中的元素的属性。
Command Object 类似如下:
public class CommandObject {
private List&ListElement& mylist = new ArrayList&ListElement&();
// getter and setter
这里list属性必须先行实例化,否则会错误。这个与Hibernate要求PO的一对多Set必须实例化一样。
页面大致如下:
&input type="text" name="command.xxxlist[0].name" value="" /&
&input type="text" name="command.xxxlist[1].name" value="" /&
&input type="text" name="command.xxxlist[2].name" value="" /&
运行后会报错, 由于绑定的时候list为empty, xxxlist.get(index)自然会数组越界,name要set都不知set到哪里去了。Spring也不会自行实例化,这让我感到相当恼火。
研读Source Code,寻求解决方法,不禁释然:当前版本要兼容1.4,Spring要如何知道实例化哪个Class,在没有使用泛型的情况下。
追踪代码,核心在org.springframework.beans.BeanWrapperImpl.java中。
private Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
String propertyName = tokens.canonicalN
String actualName = tokens.actualN
PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName);
if (pd == null || pd.getReadMethod() == null) {
throw new NotReadablePropertyException(getRootClass(), this.nestedPath + propertyName);
Method readMethod = pd.getReadMethod();
if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
readMethod.setAccessible(true);
Object value = readMethod.invoke(this.object, (Object[]) null);
if (tokens.keys != null) {
// apply indexes and map keys
for (int i = 0; i & tokens.keys. i++) {
String key = tokens.keys[i];
if (value == null) {
throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + propertyName,
"Cannot access indexed value of property referenced in indexed " +
"property path '" + propertyName + "': returned null");
else if (value.getClass().isArray()) {
value = Array.get(value, Integer.parseInt(key));
else if (value instanceof List) {
List list = (List)
value = list.get(Integer.parseInt(key));
else if (value instanceof Set) {
// Apply index to Iterator in case of a Set.
Set set = (Set)
int index = Integer.parseInt(key);
if (index & 0 || index &= set.size()) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Cannot get element with index " + index + " from Set of size " +
set.size() + ", accessed using property path '" + propertyName + "'");
Iterator it = set.iterator();
for (int j = 0; it.hasNext(); j++) {
Object elem = it.next();
if (j == index) {
else if (value instanceof Map) {
Map map = (Map)
Class mapKeyType =
if (JdkVersion.isAtLeastJava15()) {
mapKeyType = GenericCollectionTypeResolver.getMapKeyReturnType(pd.getReadMethod(), i + 1);
// IMPORTANT: Do not pass full property name in here - property editors
// must not kick in for map keys but rather only for map values.
Object convertedMapKey = this.typeConverterDelegate.convertIfNecessary(key, mapKeyType);
// Pass full property name and old value in here, since we want full
// conversion ability for map values.
value = map.get(convertedMapKey);
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Property referenced in indexed property path '" + propertyName +
"' is neither an array nor a List nor a Set nor a M returned value was [" + value + "]");
catch (InvocationTargetException ex) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Getter for property '" + actualName + "' threw exception", ex);
catch (IllegalAccessException ex) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Illegal attempt to get property '" + actualName + "' threw exception", ex);
catch (IndexOutOfBoundsException ex) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Index of out of bounds in property path '" + propertyName + "'", ex);
catch (NumberFormatException ex) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Invalid index in property path '" + propertyName + "'", ex);
于是决定改Source了,具体如下。顺便还发现Map也有同样问题,便一道改了。
private Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
String propertyName = tokens.canonicalN
String actualName = tokens.actualN
PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName);
if (pd == null || pd.getReadMethod() == null) {
throw new NotReadablePropertyException(getRootClass(), this.nestedPath + propertyName);
Method readMethod = pd.getReadMethod();
if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
readMethod.setAccessible(true);
Object value = readMethod.invoke(this.object, (Object[]) null);
if (tokens.keys != null) {
// apply indexes and map keys
for (int i = 0; i & tokens.keys. i++) {
String key = tokens.keys[i];
if (value == null) {
throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + propertyName,
"Cannot access indexed value of property referenced in indexed " +
"property path '" + propertyName + "': returned null");
else if (value.getClass().isArray()) {
value = Array.get(value, Integer.parseInt(key));
else if (value instanceof List) {
List list = (List)
int positionOfList = Integer.parseInt(key);
Class listElementClass = GenericCollectionTypeResolver.getCollectionReturnType(readMethod);
if(list.size() &= positionOfList && JdkVersion.isAtLeastJava15()
&& listElementClass != null
&& !(ClassUtils.isPrimitiveOrWrapper(listElementClass)
|| listElementClass.equals(String.class))) {
if(positionOfList & Byte.MAX_VALUE) {
throw new IllegalAccessException("Invalid property '" + nestedPath + propertyName + "' of ["
+ getRootClass() + "] : "
+ positionOfList
+ " is too large to support (max value is "
+ Byte.MAX_VALUE
for(int j = list.size(); j & positionOfL j++) {
Object listElement = BeanUtils.instantiateClass(listElementClass);
list.add(listElement);
value = BeanUtils.instantiateClass(listElementClass);
list.add(value);
value = list.get(positionOfList);
else if (value instanceof Set) {
// Apply index to Iterator in case of a Set.
Set set = (Set)
int index = Integer.parseInt(key);
if (index & 0 || index &= set.size()) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Cannot get element with index " + index + " from Set of size " +
set.size() + ", accessed using property path '" + propertyName + "'");
Iterator it = set.iterator();
for (int j = 0; it.hasNext(); j++) {
Object elem = it.next();
if (j == index) {
else if (value instanceof Map) {
Map map = (Map)
Class mapKeyType =
Class mapValueType =
if (JdkVersion.isAtLeastJava15()) {
mapKeyType = GenericCollectionTypeResolver.getMapKeyReturnType(readMethod, i + 1);
mapValueType = GenericCollectionTypeResolver.getMapValueReturnType(readMethod, i + 1);
// IMPORTANT: Do not pass full property name in here - property editors
// must not kick in for map keys but rather only for map values.
Object convertedMapKey = this.typeConverterDelegate.convertIfNecessary(key, mapKeyType);
// Pass full property name and old value in here, since we want full
// conversion ability for map values.
value = map.get(convertedMapKey);
if(value == null && mapValueType != null
&& !(ClassUtils.isPrimitiveOrWrapper(mapValueType)
|| mapValueType.equals(String.class))) {
value = BeanUtils.instantiateClass(mapValueType);
map.put(convertedMapKey, value);
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Property referenced in indexed property path '" + propertyName +
"' is neither an array nor a List nor a Set nor a M returned value was [" + value + "]");
catch (InvocationTargetException ex) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Getter for property '" + actualName + "' threw exception", ex);
catch (IllegalAccessException ex) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Illegal attempt to get property '" + actualName + "' threw exception", ex);
catch (IndexOutOfBoundsException ex) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Index of out of bounds in property path '" + propertyName + "'", ex);
catch (NumberFormatException ex) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Invalid index in property path '" + propertyName + "'", ex);
虽然代码有点难看,毕竟解决了问题。最后顺便提下,Spring内部的工具类相当给力,大大减轻了了修改工作量。^_^
浏览: 43514 次
来自: 广州
kjwxj 写道发现问题了,xml是可以直接这样引用的,但是在 ...
发现问题了,xml是可以直接这样引用的,但是在编译的时候xml ...
又诡异了,没做任何修改,就这样整,放在main下面又可以直接引 ...
那hibernate的xml的怎么加载呢,这个都是放在main ...

我要回帖

更多关于 springmvc 容器管理 的文章

 

随机推荐