簡體   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