Spring notes 1

来源:互联网 发布:开源视频网站 php 编辑:程序博客网 时间:2024/06/11 05:11

DI

  • xml configuration
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"Listing 1.5 SlayDragonQuest is a Quest to be injected into BraveKnightListing 1.6 Injecting a SlayDragonQuest into a BraveKnight with Springwww.it-ebooks.infoSimplifying Java development 9xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="knight" class="com.springinaction.knights.BraveKnight"><constructor-arg ref="quest" /></bean><bean id="quest" class="com.springinaction.knights.SlayDragonQuest"><constructor-arg value="#{T(System).out}" /></bean></beans>
  • annonation
@Configurationpublic class KnightConfig {@Beanpublic Knight knight() {return new BraveKnight(quest());}@Beanpublic Quest quest() {return new SlayDragonQuest(System.out);}}

AOP

<aop:config>    <aop:aspect ref="minstrel">        <aop:pointcut id="embark"        expression="execution(* *.embarkOnQuest(..))"/>        <aop:before pointcut-ref="embark"                    method="singBeforeQuest"/>        <aop:after pointcut-ref="embark"                    method="singAfterQuest"/>    </aop:aspect></aop:config>

application context

  • AnnotationConfigApplicationContext—Loads a Spring application context from one or more Java-based configuration classes
  • AnnotationConfigWebApplicationContext—Loads a Spring web application context from one or more Java-based configuration classes
  • ClassPathXmlApplicationContext—Loads a context definition from one or more XML files located in the classpath, treating context-definition files as classpath resources
  • FileSystemXmlApplicationContext—Loads a context definition from one or more XML files in the filesystem
  • XmlWebApplicationContext—Loads context definitions from one or more XML files contained in a web application

spring framework

0 0