bean 的 xml 文件中 单标签和一对标签有区别吗?

2020-08-25 17:07:44 +08:00
 gzk329
    <bean id="helloWorld" class="com.gzk.HelloWorld" scope="singleton" >
        <property name="message" value="Hello World!"/>
    </bean>

    <bean class="com.gzk.InitHelloWorld" /> 
<!--这句话不加</bean> 也是一个 initHelloWorld 类的对象的意思吗?-->
953 次点击
所在节点    Java
4 条回复
gzk329
2020-08-25 17:11:37 +08:00
是不是要加别的参数的时候用一对标签? 不然的话就可以省略?
如果是这样的化那是我傻了
gzk329
2020-08-25 17:12:50 +08:00
但是这句话连 id 都能省掉了嘛
lxk11153
2020-08-25 17:25:45 +08:00
1. 可以省略,如果没子标签
2. 属性能否省略你得看实现呀,spring-bean 的 id 实现是有默认 id 生成策略的,默认是类名+序号吧
stevenkang
2020-08-25 17:25:57 +08:00
找到一点资料:
https://www.w3.org/standards/xml/core.html

All elements must be closed or marked as empty.

Empty elements can be closed as normal, <happiness></happiness> or you can use a special short-form, <happiness /> instead.

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/701343

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX