春天避免豆类:豆类和写豆代替?

时间:2012-03-28 02:13:58

标签: java spring java-ee

这是有效的:

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

事实并非如此。但是,我发现这种配置更好。我应该如何对命名空间进行以下配置工作?

另外,我可以在constructor-arg中传递idref吗?这对我来说似乎不起作用。构造函数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>

2 个答案:

答案 0 :(得分:0)

您可以使用以下内容:

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

示例here

对于inject constuctor,您可以使用:

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

Spring documentation for inject constructor

答案 1 :(得分:0)

看起来你可能在第二个版本中有拼写错误。我想这个:

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

应该是这样的:

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

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