Spring中applicationContext的配置详细

配置文件

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc"  
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd"
        default-lazy-init="true"  default-init-method="init"
        default-destroy-method="destroy">
    <!-- 使用构造器 -->
        <bean id="caleadar" class="java.util.GregorianCalendar"></bean>
        <!-- 使用静态工厂方法 -->
        
        <bean id="c2" class="java.util.Calendar" factory-method="getInstance"></bean><!--
        
        <bean id="c3" class="java.util.GregorianCalendar">
         
                   <bean id="cc3" factory-bean="c3" factory-method="getTime"></bean>
         </bean>

-->
   <bean id="calendarObj3" class="java.util.GregorianCalendar"></bean>
    <bean id="cc4" factory-bean="calendarObj3" factory-method="getTime">
    </bean>

 <bean id="exampleBean" class="com.baosight.bean.ExampleBean"></bean>

</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <description>Spring公共配置文件</description> <!-- mes 的數據庫 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/> <property name="jdbcUrl" value="jdbc:oracle:thin:@10.142.252.132:1521:mestest"/> <property name="maxPoolSize" value="10"></property> <property name="maxIdleTime" value="1800"></property> <property name="minPoolSize" value="1"></property> <property name="initialPoolSize" value="1"></property> <property name="properties"> <ref bean="mesDatasourcePropertiesFactory" /> </property> </bean> <!-- c3p0数据源的一个专有属性,只可以存放密码和用户名 --> <bean id="mesDatasourcePropertiesFactory" class="com.ccc.db.impl.DatasourcePropertiesFactory" factory-method="getProperties"> <!-- userName--> <constructor-arg type="java.lang.String"> <value>jxg/Qr4VbxU=</value> </constructor-arg> <!-- password --> <constructor-arg type="java.lang.String"> <value>jxg/Qr4VbxU=</value> </constructor-arg> <!-- 生产环境模式 ,才特殊处理加密密码--> <constructor-arg type="java.lang.String"> <value>true</value> </constructor-arg> </bean> <!-- ptc windchill的數據庫 --> <bean id="dataSourcePdm" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/> <property name="jdbcUrl" value="jdbc:oracle:thin:@10.142.252.132:1521:mesdev"/> <property name="maxPoolSize" value="10"></property> <property name="maxIdleTime" value="1800"></property> <property name="minPoolSize" value="1"></property> <property name="initialPoolSize" value="1"></property> <property name="properties"> <ref bean="ptcDatasourcePropertiesFactory" /> </property> </bean> <!-- c3p0数据源的一个专有属性,只可以存放密码和用户名 --> <bean id="ptcDatasourcePropertiesFactory" class="com.ccc.db.impl.DatasourcePropertiesFactory" factory-method="getProperties"> <!-- userName--> <constructor-arg type="java.lang.String"> <value>WgDH/SDIJfs=</value> </constructor-arg> <!-- password --> <constructor-arg type="java.lang.String"> <value>WgDH/SDIJfs=</value> </constructor-arg> <!-- 生产环境模式 ,才特殊处理加密密码--> <constructor-arg type="java.lang.String"> <value>true</value> </constructor-arg> </bean> <!-- mes數據源代理 --> <bean id="dataSourceProxy" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy" p:targetDataSource-ref="dataSource"/> <!-- 对web包的所有类进行扫描,以完成Bean创建和自动依赖注入的功能--> <context:component-scan base-package="com.ccc"/> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" p:order="0" /> <!-- 配置事务管理器 針對MES數據庫--> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager " p:dataSource-ref="dataSourceProxy"/> <!-- 配置事务的传播特性 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED"/> <tx:method name="insert*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="*" read-only="true"/> </tx:attributes> </tx:advice> <!-- 那些类的哪些方法参与事务 --> <aop:config> <aop:pointcut id="allManagerMethod" expression="execution(* com.ccc..*.*(..))"/> <aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/> </aop:config> <!-- 配置事务管理器,這個事務性是爭對pdm數據庫的 --> <bean id="transactionManagerPdm" class="org.springframework.jdbc.datasource.DataSourceTransactionManager " p:dataSource-ref="dataSourcePdm"/> <!-- 配置事务的传播特性 --> <tx:advice id="txAdvicePdm" transaction-manager="transactionManagerPdm"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED"/> <tx:method name="insert*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="*" read-only="true"/> </tx:attributes> </tx:advice> <!-- 那些类的哪些方法参与事务 --> <aop:config> <aop:pointcut id="allManagerMethodPdm" expression="execution(* com.ccc.pdm..*.*(..))"/> <aop:advisor pointcut-ref="allManagerMethodPdm" advice-ref="txAdvicePdm"/> </aop:config> <!-- ibatis插件 --> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean" p:dataSource-ref="dataSourceProxy"> <property name="configLocation"> <value>classpath:SqlMapConfig.xml</value> </property> </bean> <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate"> <property name="sqlMapClient"> <ref bean="sqlMapClient" /> </property> </bean> <!-- 配置要拦截的url,防止2次提交或做其他數據統計用 <bean id="doubleSubmitInterceptor" class="com.ccc.filter.DoubleSubmitInterceptor"> <property name="mappingURL" value=".html" /> <property name="viewURL" value=".html" /> </bean> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" p:order="0"> <property name="interceptors"> <list> <ref bean="doubleSubmitInterceptor"/> </list> </property> </bean> --> <!-- JDBC template注入及事務配置 --> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource"><ref bean="dataSourceProxy"/></property> </bean> </beans>
### 回答1: SpringApplicationContext是一个接口,它是Spring框架的核心接口之一。它是一个Bean工厂,用于管理应用程序的Bean对象。ApplicationContext提供了一种机制,可以在应用程序轻松地创建、配置和管理Bean对象。它还提供了一些高级功能,如事件发布、国际化、资源加载和AOP等。ApplicationContextSpring框架的核心,它为应用程序提供了依赖注入和面向切面编程等重要功能。 ### 回答2: SpringApplicationContext是一个重要的容器,用于管理Spring应用程序的所有组件,并协调它们之间的协作。它是应用程序的核心,提供了BeanFactory的所有功能,并且还提供了许多其他功能。 一些关键点如下: 1. ApplicationContext使用Spring IoC容器来实现依赖注入:它将组件实例化并将它们注入到实例的其他组件,这使得应用程序更为松散耦合、更容易测试和维护。 2. ApplicationContext是BeanFactory的超集:它包含了所有BeanFactory的功能,并增加了许多其他功能,例如Event Handling、国际化、AOP等。 3. ApplicationContext的生命周期也比BeanFactory更长:它可以管理多个BeanFactory实例,并根据应用程序所需进行必要的配置,从而使Spring应用程序的生命周期更加灵活和可控。 4. ApplicationContext的实现可以是不同的,例如ClassPathXmlApplicationContext、FileSystemXmlApplicationContext等:根据应用程序的需求选择相应的ApplicationContext进行实例化和配置。 总之,ApplicationContextSpring容器的核心组件,提供了Spring应用程序的依赖注入、比BeanFactory更多的功能等,是一个重要的管理和协调组件。 ### 回答3: Spring框架是目前业界使用最为广泛的java开发框架之一,其提供的IOC和AOP功能,让开发人员能够更加轻松的实现开发任务,提高了开发效率,并且更好的维护了代码的可阅读性与灵活性。其ApplicationContextSpring框架的一个重要类,其作用是管理bean的生命周期。 ApplicationContext是一个面向Spring框架的对象容器,其负责创建、初始化和协调bean的创建与之间的关系。它是一个在应用程序运行时用于加载bean定义(配置文件或注解方式等)的类,并将这些bean添加到容器,并在接收到请求时提供这些bean。 ApplicationContext容器可以使用多种不同的实现方式,如XML文件、注解方式等,从而支持各种不同的应用场景。例如,当我们需要在应用动态的加载bean时,就可以使用XML方式来配置容器,当我们需要更加轻量级的容器时,可以使用Annotation方式来实现。无论使用何种方式,所有的bean的定义都是被装配到对应的ApplicationContext容器ApplicationContext对比BeanFactory有很多优势,其主要的优势是使得Spring容器的启动速度更快,可以提供更好的性能以及更好的功能。 ApplicationContext会在容器启动时立即处理所有的Bean定义和之前定义为“懒加载”的Bean,而BeanFactory在使用时才会去解析或懒加载Bean,因此在启动时会比较卡。 总而言之,ApplicationContextSpring框架的一个十分重要的类,它能够管理bean的生命周期,用于加载bean的定义,为应用程序提供Bean的实例,并且提供了很多的功能和优势。学习和了解ApplicationContext的使用方式,对于掌握Spring框架及其相关技术是非常重要的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值