配置元数据

配置元数据

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
        https://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="..." class="..."> (1) (2)
        <!-- 这个Bean的“合作者”和配置在这里 -->
    </bean>

    <bean id="..." class="...">
        <!-- 这个Bean的“合作者”和配置在这里  -->
    </bean>

    <!-- 更多Bean定义在这里 -->

</beans>

实例化对象

ApplicationContext context = new ClassPathXmlApplicationContext("services.xml", "daos.xml");

让bean在多个xml配置都可以使用

<beans>
    <import resource="services.xml"/>
    <import resource="resources/messageSource.xml"/>
    <import resource="/resources/themeSource.xml"/>

    <bean id="bean1" class="..."/>
    <bean id="bean2" class="..."/>
</beans>

在java中

@Configuration
public class config{
  @Bean
  public 
}
posted @ 2022-11-26 18:40  壹剑霜寒十四州  阅读(13)  评论(0编辑  收藏  举报