Skip to content

Commit

Permalink
✨ Introducing new features.three method bean lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
crossoverJie committed Mar 20, 2018
1 parent bf5b52c commit b70fd0d
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/java/com/crossoverjie/spring/LifeCycleConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.crossoverjie.spring;

import com.crossoverjie.concurrent.Singleton;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
* Function:
*
* @author crossoverJie
* Date: 19/03/2018 22:37
* @since JDK 1.8
*/
@Configuration
public class LifeCycleConfig {


@Bean(initMethod = "start", destroyMethod = "destroy")
public SpringLifeCycle create(){
SpringLifeCycle springLifeCycle = new SpringLifeCycle() ;

return springLifeCycle ;
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/crossoverjie/spring/SpringLifeCycle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.crossoverjie.spring;

import com.crossoverjie.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
* Function:
*
* @author crossoverJie
* Date: 20/03/2018 18:23
* @since JDK 1.8
*/
public class SpringLifeCycle{

private final static Logger LOGGER = LoggerFactory.getLogger(SpringLifeCycle.class);
public void start(){
LOGGER.info("SpringLifeCycle start");
}


public void destroy(){
LOGGER.info("SpringLifeCycle destroy");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.crossoverjie.spring.annotation;

import com.crossoverjie.spring.SpringLifeCycle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
* Function:
*
* @author crossoverJie
* Date: 20/03/2018 18:46
* @since JDK 1.8
*/
@Component
public class AnnotationBean {
private final static Logger LOGGER = LoggerFactory.getLogger(AnnotationBean.class);

@PostConstruct
public void start(){
LOGGER.info("AnnotationBean start");
}

@PreDestroy
public void destroy(){
LOGGER.info("AnnotationBean destroy");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.crossoverjie.spring.service;

import com.crossoverjie.spring.SpringLifeCycle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
* Function:首先执行
*
* @author crossoverJie
* Date: 20/03/2018 18:38
* @since JDK 1.8
*/
@Service
public class SpringLifeCycleService implements InitializingBean,DisposableBean{
private final static Logger LOGGER = LoggerFactory.getLogger(SpringLifeCycleService.class);
@Override
public void destroy() throws Exception {
LOGGER.info("SpringLifeCycleService destroy");
}

@Override
public void afterPropertiesSet() throws Exception {
LOGGER.info("SpringLifeCycleService start");
}
}

0 comments on commit b70fd0d

Please sign in to comment.