java – Spring 3 applicationContext-security-JDBC. XML has beans: are beans not beans?
Someone can tell me that I have to use beans in my ApplicationContext: beans instead of beans and how to fix it
<?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"> <http auto-config="true" use-expressions="true"> <intercept-url pattern="/friends/**" access="hasRole('ROLE_USER')" /> <form-login login-page="/login.html" default-target-url="/index.html" always-use-default-target="true" authentication-failure-url="/login.html?authFailed=true" /> </http> <authentication-manager alias="authenticationManager"> <authentication-provider> <jdbc-user-service data-source-ref="dataSource" /> </authentication-provider> </authentication-manager> <beans:bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <beans:property name="location" value="classpath:jdbc.properties" /> </beans:bean> <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <beans:property name="driverClassName" value="${database.driver}" /> <beans:property name="url" value="${database.url}" /> <beans:property name="username" value="${database.user}" /> <beans:property name="password" value="${database.password}" /> <beans:property name="initialSize" value="5" /> <beans:property name="maxActive" value="10" /> </beans:bean> </beans:beans>
Solution
explain. Basically, you deal with XML namespaces here Spring configuration allows you to use configuration elements from different namespaces as a way to extend the basic bean namespace configuration, and use convenient domain specific configurations, such as the above security configuration
If your configuration file focuses on one of the extended namespaces – again, let's use security as an example – if you declare the default namespace as an extended namespace instead of a standard bean namespace, it can clean up the file What's that?
xmlns="http://www.springframework.org/schema/security"
Indeed - it makes security the default namespace, which means you don't have to use sec: or security: as a prefix
However, when you set security to the default value, you must be explicit when using beans namespace elements So bean: prefix
Solution If you prefer beans as the default, just change the default namespace to beans:
xmlns="http://www.springframework.org/schema/beans"
Alternatives Or, if you want to enter something shorter, you can do so
xmlns:b="http://www.springframework.org/schema/beans"
replace
xmlns:beans="http://www.springframework.org/schema/beans"
This will allow you to do things
<b:bean id="beanId" class="x.y.z.BeanClass" />