了解spring @Configuration类

在理解“ Spring @Autowired用法”这个问题之后,我想为弹簧接线的另一个选项(@Configuration类)创建一个完整的知识库。


假设我有一个看起来像这样的spring XML文件:


<?xml version="1.0" encoding="UTF-8"?>

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

  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">


  <import resource="another-application-context.xml"/>


  <bean id="someBean" class="stack.overflow.spring.configuration.SomeClassImpl">

    <constructor-arg value="${some.interesting.property}" />

  </bean>


  <bean id="anotherBean" class="stack.overflow.spring.configuration.AnotherClassImpl">

    <constructor-arg ref="someBean"/>

    <constructor-arg ref="beanFromSomewhereElse"/>

  </bean>

</beans>

我该如何使用@Configuration呢?它对代码本身有影响吗?


杨__羊羊
浏览 500回答 3
3回答

牛魔王的故事

这是一个很好的论据,我已经听过几次了。而且我尝试进行一些统计研究,在其中我找不到在jars / wars之外使用XML的任何应用程序或系统。它的实际含义是您需要解压缩jar并更改XML(我找不到找到它的人)或重建您的jar(这是我与之交谈的所有人到目前为止所做的事情) 。因此,底线-尽管可能是一个相当大的论点,但在现实生活中通常并不重要。&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP