繁体   English   中英

春天避免使用bean:beans而是编写bean?

[英]Spring avoiding beans:beans and writing beans instead?

这正在工作:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-3.0.xsd">

    <beans:bean id="test2" name="name" class="org.chicago.home.Test2"> </beans:bean>

    <beans:bean id="test1" class="org.chicago.home.Test1">
        <beans:constructor-arg ref="test2"/>
    </beans:bean>
</beans:beans>

这不是。 但是,我发现这种类型的配置更好。 我应该对名称空间做些什么,以使以下配置起作用?

另外,我可以在builder-arg中传递idref吗? 这似乎对我不起作用。 Constructor-arg中的idref bean =“”和idref local =“”均不起作用。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/security"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-3.0.xsd">

    < I am pressing Ctrl + Space here, but it says beans doesn't have any child tags. 

</beans>

您可以使用类似:

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

这里的例子

对于注入构造器,可以使用:

<constructor-arg><ref bean="anotherExampleBean"/></constructor-arg>

用于Inject构造函数的Spring文档

您似乎在第二个版本中有错别字。 我认为这:

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

应该是这样的:

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

除非您只是复制错误。 如果这不能解决问题,您可以发布错误消息吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM