<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                1.6.1 生命周期回調 實現接口: InitializingBean? DisposableBean? 可以使用afterPropertiesSet()?和destroy() 執行特定的功能。 JSR-250?規定使用@PostConstruct?and?@PreDestroy注解,但是這個不會與spring的特定接口結合。也就是不會走到Spring的特定接口。 Spring 使用 BeanPostProcessor?, -初始化回調 org.springframework.beans.factory.InitializingBean void afterPropertiesSet() throws Exception; 不推薦使用InitializingBean?的接口,因為會與Spring進行不必要的耦合。使用 @PostConstruct? 或者指定POJO指定方法。 xml使用 init-method, Java使用 intiMethod <bean id="exampleInitBean" class="examples.ExampleBean" init-method="init"/> public class ExampleBean { public void init() { // do some initialization work } } } 雖然與以下等效,但是不會與Spring耦合 <bean id="exampleInitBean" class="examples.AnotherExampleBean"/> public class AnotherExampleBean implements InitializingBean { public void afterPropertiesSet() { // do some initialization work } } } -銷毀回調 org.springframework.beans.factory.DisposableBean void destroy() throws Exception; 不建議使用DisposableBean?回調接口,應為會和Spring有不必要的耦合。 可以使用@PreDestroy?, 在XML中bean配置 destroy-method <bean id="exampleInitBean" class="examples.ExampleBean" destroy-method="cleanup"/> 在Java中, 使用Bean中的destroyMethod. <bean id="exampleInitBean" class="examples.ExampleBean" destroy-method="cleanup"/> public class ExampleBean { public void cleanup() { // do some destruction work (like releasing pooled connections) } } } 與以下等效:以下方式不好,與Spring 耦合 <bean id="exampleInitBean" class="examples.AnotherExampleBean"/> public class AnotherExampleBean implements DisposableBean { public void destroy() { // do some destruction work (like releasing pooled connections) } } } -默認初始和銷毀方法 可以指定初始化的方法: <beans default-init-method="init"> <bean id="blogService" class="com.foo.DefaultBlogService"> <property name="blogDao" ref="blogDao" /> </bean> </beans> 代碼中新增這個方法: public class DefaultBlogService implements BlogService { private BlogDao blogDao; public void setBlogDao(BlogDao blogDao) { this.blogDao = blogDao; } // this is (unsurprisingly) the initialization callback method public void init() { if (this.blogDao == null) { throw new IllegalStateException("The [blogDao] property must be set."); } } } } 同樣銷毀可以使用 default-destroy-method 的配置 對同一個bean的多個生命周期機制,可以使用不同的初始化方法,順序如下 1- @PostConstruct 的注釋 2- afterPropertiesSet() 定義在InitializingBean? 接口的 3. 定制的 init() 方法 銷毀的順序也是類似: 1. @PreDestroy 注釋 2. destroy()? 方法 繼承自DisposableBean? 3.定制的destroy() 方法。 在依賴項開始之前開始,在依賴項結束之后結束。 SmartLifecycle接口,可以得到對象的階段。 Spring web 的ApplicationContext已經處理了關閉Spring IoC 容器。 非web應用程式需要處理。 registerShutdownHook() import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public final class Boot { public static void main(final String[] args) throws Exception { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml"); // add a shutdown hook for the above context... ctx.registerShutdownHook(); // app runs here... // main method exits, hook is called prior to the app shutting down... } } } 1.6.2 ApplicationContextAware? 和 BeanNameAware 從ApplicationContextAware接口繼承,當創建一個ApplicationContext是,提供了以下設置方式: public interface ApplicationContextAware { void setApplicationContext(ApplicationContext applicationContext) throws BeansException; } } BeanNameAware 類似狀況 public interface BeanNameAware { void setBeanName(String name) throws BeansException; } } 1.6.3 其他Aware接口 Name Injected Dependency Explained in…? ApplicationContextAware Declaring?ApplicationContext ApplicationContextAware and BeanNameAware ApplicationEventPublisherAware Event publisher of the enclosing?ApplicationContext Additional capabilities of the ApplicationContext BeanClassLoaderAware Class loader used to load the bean classes. Instantiating beans BeanFactoryAware Declaring?BeanFactory ApplicationContextAware and BeanNameAware BeanNameAware Name of the declaring bean ApplicationContextAware and BeanNameAware BootstrapContextAware Resource adapter?BootstrapContext?the container runs in. Typically available only in JCA aware?ApplicationContexts JCA CCI LoadTimeWeaverAware Defined?weaver?for processing class definition at load time Load-time weaving with AspectJ in the Spring Framework MessageSourceAware Configured strategy for resolving messages (with support for parametrization and internationalization) Additional capabilities of the ApplicationContext NotificationPublisherAware Spring JMX notification publisher Notifications ResourceLoaderAware Configured loader for low-level access to resources Resources ServletConfigAware Current?ServletConfig?the container runs in. Valid only in a web-aware SpringApplicationContext Spring MVC ServletContextAware Current?ServletContext?the container runs in. Valid only in a web-aware SpringApplicationContext Spring MVC Aware的用法沒有follow IoC的風格。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看