gpt4 book ai didi

java - Spring 3 applicationContext-security-JDBC.xml 有 bean :bean not bean?

转载 作者:数据小太阳 更新时间:2023-10-29 02:21:15 25 4
gpt4 key购买 nike

有人可以告诉我在我的 ApplicationContext 中我必须使用 beans:bean 而不是 bean 的什么以及如何修复它。

<?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>

最佳答案

说明。基本上,您在这里处理的是 XML 命名空间。 Spring 配置允许您使用来自不同命名空间的配置元素作为一种扩展基本 beans 命名空间配置的方式,具有方便的特定于域的配置,如上述案例中的安全配置。

如果您的配置文件集中在这些扩展命名空间之一——再次,让我们以安全性为例——如果您将默认命名空间声明为扩展命名空间而不是标准 beans 命名空间。就是这样

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

是——它使 security 成为默认命名空间,这意味着您不必在它前面加上 sec:security: 前缀。

但是当您将 security 设置为默认值时,则在使用 beans 命名空间元素时必须明确。因此 beans: 前缀。

解决方案。如果您希望将 beans 作为默认命名空间,只需将默认命名空间更改为 beans:

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

替代解决方案。或者,如果您想输入更短的内容,您可以这样做

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

代替

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

这将允许你做类似的事情

<b:bean id="beanId" class="x.y.z.BeanClass" />

关于java - Spring 3 applicationContext-security-JDBC.xml 有 bean :bean not bean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5607230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com