在进行 SSI整合时,老是报下边的错误: nested exception is java.lang.IllegalArgumentException: Property 'sqlMapClient' is required java
详细的错误信息以下:spring
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlMapClient' is requiredsql
在配置文件applicationContext中查看后发现配置中没有properties标签,很明显是没有将sqlMapClien注入到personDao中:app
<bean id="personDao" class="com.zaj.dao.PersonDao"/>
正常思惟就是将已经注册的sqlMapClient注入到personDao中,修改以下:ide
<bean id="personDao" class="com.zaj.dao.PersonDao"> <property name="sqlMapClient" ref="sqlMapClient"></property> </bean>
试运行,没错,运行正确,错误没了。但是我对照事例中的xml文件,明明是没有这个properties的,这究竟是为何?仔细对比,发如今事例的xml文件头里边,有一个属性,以下:学习
default-autowire="byName"
按着事例的样子,把属性加上,注释掉刚才新加的properties,再次运行,果真能够,看到byName,想起来原来好像听马哥(马士兵)说过,有byName和byType自动加载的属性,基于学习起见,找出spring的参考文档,找啊找,终于找到下边的内容:ui
Optional attribute controlling whether to "autowire" bean properties. This is an automagical process in which bean references don't need to be coded explicitly in the XML bean definition file, but Spring works out dependencies. There are 5 modes: 1. "no" No automagical wiring. Bean references must be defined in the XML file via the <ref> element. We recommend this in most cases as it makes documentation more explicit. Autowiring by property name. If a bean of class Cat exposes a dog property, Spring will try to set this to the value of the bean "dog" in the current factory. 3. "byType" Autowiring if there is exactly one bean of the property type in the bean factory. If there is more than one, a fatal error is raised, and you can't use byType autowiring for that bean. If there is none, nothing special happens; use dependency-check="objects" to raise an error in that case. 4. "constructor" Analogous to "byType" for constructor arguments. If there isn't exactly one bean of the constructor argument type in the bean factory, a fatal error is raised. 5. "autodetect" Chooses "constructor" or "byType" through introspection of the bean class. If a default constructor is found, "byType" gets applied. The latter two are similar to PicoContainer and make bean factories simple to configure for small namespaces, but doesn't work as well as standard Spring behaviour for bigger applications. Note that explicit dependencies, i.e. "property" and "constructor-arg" elements, always override autowiring. Autowire behavior can be combined with dependency checking, which will be performed after all autowiring has been completed. Note: This attribute will not be inherited by child bean definitions. Hence, it needs to be specified per concrete bean definition.意思是若是被bean中暴露出来一个bean后,若是找不到被暴露出来的这个bean,不会报错,可是若是使用dependency-check="objects"则会报错,可是我是什么都没有暴露他出的错误啊,又仔细看发现mode ‘no’,人家明显写着The traditional Spring default.说默认是no,就是说默认不会自动wire,必须在xml文件中手动注入,手动链接,这下就明白了,原来没写default-autowire="byName"的时候是找不到sqlMapClient的,由于默认使用的是no!后来我就试了一下byType彻底没有影响啊,估计是由于个人id都是惟一的,其余的就没有再试了,有兴趣你们能够本身试。 这下就对这个错误了解比较深了,也对spring配置有所了解,但愿对遇见这个错误的同窗有所帮助。