-
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.
- Loading branch information
Showing
4 changed files
with
89 additions
and
48 deletions.
There are no files selected for viewing
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
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
44 changes: 6 additions & 38 deletions
44
bow/src/main/java/com/amor/bow/listener/PropertiesModifiedListener.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 |
---|---|---|
@@ -1,55 1,23 @@ | ||
package com.amor.bow.listener; | ||
|
||
import com.amor.bow.config.BowProxyProperties; | ||
import com.amor.bow.helper.SpringBeanHolder; | ||
import com.amor.bow.listener.event.PropertiesModifiedEvent; | ||
import com.amor.bow.repository.impl.UserLoader; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; | ||
import org.springframework.boot.bind.PropertiesConfigurationFactory; | ||
import org.springframework.boot.context.config.ConfigFileApplicationListener; | ||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; | ||
import org.springframework.context.ApplicationEvent; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.core.io.support.SpringFactoriesLoader; | ||
import org.springframework.validation.BindException; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by dell on 2017/10/25. | ||
*/ | ||
public class PropertiesModifiedListener extends ConfigFileApplicationListener{ | ||
public class PropertiesModifiedListener implements ApplicationListener<PropertiesModifiedEvent> { | ||
|
||
private final static Logger logger = LoggerFactory.getLogger(PropertiesModifiedListener.class); | ||
|
||
private ApplicationEnvironmentPreparedEvent environmentPreparedEvent = null; | ||
@Override | ||
public void onApplicationEvent(ApplicationEvent event) { | ||
if(event instanceof ApplicationEnvironmentPreparedEvent){ | ||
this.environmentPreparedEvent = (ApplicationEnvironmentPreparedEvent)event; | ||
} | ||
if(event instanceof PropertiesModifiedEvent){ | ||
logger.info("listen a prpperties modified event,reload the properties."); | ||
AutowireCapableBeanFactory beanFactory = SpringBeanHolder.getContext() | ||
.getAutowireCapableBeanFactory(); | ||
|
||
BowProxyProperties properties = SpringBeanHolder.getBean(BowProxyProperties.class); | ||
if(null != properties){ | ||
beanFactory.destroyBean(properties); | ||
} | ||
postProcessEnvironment(environmentPreparedEvent.getEnvironment(),environmentPreparedEvent.getSpringApplication()); | ||
beanFactory.createBean(BowProxyProperties.class); | ||
/*List<PropertiesConfigurationFactory> propertiesConfigurationFactories = SpringFactoriesLoader. | ||
loadFactories(PropertiesConfigurationFactory.class,getClass().getClassLoader()); | ||
propertiesConfigurationFactories.forEach(factory ->{ | ||
try { | ||
factory.bindPropertiesToTarget(); | ||
} catch (BindException e) { | ||
e.printStackTrace(); | ||
} | ||
});*/ | ||
} | ||
|
||
public void onApplicationEvent(PropertiesModifiedEvent event) { | ||
logger.info("listen properties modified event,reload it!"); | ||
UserLoader loader = SpringBeanHolder.getBean(UserLoader.class); | ||
loader.reload(); | ||
} | ||
} |
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