Spring 3 applicationContext-security-JDBC.xml has beans:bean not bean?

隐身守侯 提交于 2019-12-03 08:43:16

Explanation. Basically you are dealing with XML namespaces here. Spring configuration allows you to use configuration elements from different namespaces as a way to extend the basic beans namespace configuration with convenient domain-specific configuration, like security configuration in the case above.

In cases where your configuration file concentrates on one of these extension namespaces--again, let's use security as an example--it can clean up the file if you declare the default namespace to be the extension namespace instead of the standard beans namespace. That's what

xmlns="http://www.springframework.org/schema/security"

does--it makes security the default namespace, which means you don't have to prefix it with sec: or security:.

But when you make security the default, then you have to be explicit when using beans namespace elements. Hence the beans: prefix.

Solution. If you prefer beans to be the default, just change the default namespace to beans:

xmlns="http://www.springframework.org/schema/beans"

Alternative solution. Alternatively, if you want to type something shorter, you could do

xmlns:b="http://www.springframework.org/schema/beans"

instead of

xmlns:beans="http://www.springframework.org/schema/beans"

which would allow you to do things like

<b:bean id="beanId" class="x.y.z.BeanClass" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!