您的位置:首页 > 编程语言 > Java开发

Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFa

2012-08-12 21:08 627 查看
添加上如下的一句就可以了

default-autowire="byName" default-lazy-init="true"


然后Spring的配置改为

<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"default-autowire="byName" default-lazy-init="true">


其实对于使用
default-autowire="byName" default-lazy-init="true" 
也还是要看情况来定的,搜了一下网上的,也有如下的问题
Spring default-autowire="byName"自动配置bean注入,(删掉了显示配置属性,还是可以注入,没发现这个属性的时候还以为是缓存的问题)。发现在spring中的Beans属性项中,写了这么一段“default-autowire="byName",. 恍然大悟,配置了这个属性项后,spring会对bean的属性自动按name去寻找,如果找到则set进去,而不必对Bean的属性进行显式的Set。仔细想想default-autowire="byName"应该算是最差实践吧,虽然能减少配置文件的书写量,可配置文件的可读性却大打折扣,一 个Bean你无法知道他有那些属性项,无法知道那些Bean与其相关,如果你碰巧修改了一个相关Bean而导致改Bean异常,估计要够你找的。配置文件和代码一样,应该可读性强,清晰明了,一看就能明白,而default-autowire="byName"会导致配置文件几乎无法可读,你无法明白这些bean之间的相互关系,如果是你自己维护还好,换个第三者来,估计要把写配置文件的骂个底朝天。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐