简体   繁体   English

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

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

This is working: 这正在工作:

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

This is not. 这不是。 But, I find this type of configuration better. 但是,我发现这种类型的配置更好。 What should I do to the namespace to make this below configuration work? 我应该对名称空间做些什么,以使以下配置起作用?

Also, can I pass idref in constructor-arg? 另外,我可以在builder-arg中传递idref吗? That doesn't seem to work for me. 这似乎对我不起作用。 Neither idref bean="" nor idref local="" inside constructor-arg is working. 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>

You can use something like: 您可以使用类似:

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

Example here 这里的例子

For inject constuctor, you can use: 对于注入构造器,可以使用:

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

Spring documentation for inject constructor 用于Inject构造函数的Spring文档

It looks like you might have a typo in the second version. 您似乎在第二个版本中有错别字。 I think this: 我认为这:

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

should be this: 应该是这样的:

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

Unless you just copied it wrong. 除非您只是复制错误。 If this doesn't fix it, can you post the error message? 如果这不能解决问题,您可以发布错误消息吗?

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

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