forked from crossoverJie/JCSprout
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Introducing new features.three method bean lifecycle
- Loading branch information
1 parent
bf5b52c
commit b70fd0d
Showing
4 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/java/com/crossoverjie/spring/LifeCycleConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
src/main/java/com/crossoverjie/spring/SpringLifeCycle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/crossoverjie/spring/annotation/AnnotationBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/crossoverjie/spring/service/SpringLifeCycleService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |