-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1019 from nobodyiam/0.10.1
fix the issue brought by 0.10.0 that Spring related classes are mistakenly loaded via DefaultInjector
- Loading branch information
Showing
26 changed files
with
126 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
FROM openjdk:8-jre-alpine | ||
MAINTAINER ameizi <[email protected]> | ||
|
||
ENV VERSION 0.10.0 | ||
ENV VERSION 0.10.1 | ||
|
||
RUN echo "http://mirrors.aliyun.com/alpine/v3.6/main" > /etc/apk/repositories \ | ||
&& echo "http://mirrors.aliyun.com/alpine/v3.6/community" >> /etc/apk/repositories \ | ||
|
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
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
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
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
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
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
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
53 changes: 53 additions & 0 deletions
53
apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/SpringInjector.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,53 @@ | ||
package com.ctrip.framework.apollo.spring.util; | ||
|
||
import com.ctrip.framework.apollo.exceptions.ApolloConfigException; | ||
import com.ctrip.framework.apollo.spring.config.ConfigPropertySourceFactory; | ||
import com.ctrip.framework.apollo.spring.property.PlaceholderHelper; | ||
import com.ctrip.framework.apollo.spring.property.SpringValueRegistry; | ||
import com.ctrip.framework.apollo.tracer.Tracer; | ||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Guice; | ||
import com.google.inject.Injector; | ||
import com.google.inject.Singleton; | ||
|
||
public class SpringInjector { | ||
private static volatile Injector s_injector; | ||
private static final Object lock = new Object(); | ||
|
||
private static Injector getInjector() { | ||
if (s_injector == null) { | ||
synchronized (lock) { | ||
if (s_injector == null) { | ||
try { | ||
s_injector = Guice.createInjector(new SpringModule()); | ||
} catch (Throwable ex) { | ||
ApolloConfigException exception = new ApolloConfigException("Unable to initialize Apollo Spring Injector!", ex); | ||
Tracer.logError(exception); | ||
throw exception; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return s_injector; | ||
} | ||
|
||
public static <T> T getInstance(Class<T> clazz) { | ||
try { | ||
return getInjector().getInstance(clazz); | ||
} catch (Throwable ex) { | ||
Tracer.logError(ex); | ||
throw new ApolloConfigException( | ||
String.format("Unable to load instance for %s!", clazz.getName()), ex); | ||
} | ||
} | ||
|
||
private static class SpringModule extends AbstractModule { | ||
@Override | ||
protected void configure() { | ||
bind(PlaceholderHelper.class).in(Singleton.class); | ||
bind(ConfigPropertySourceFactory.class).in(Singleton.class); | ||
bind(SpringValueRegistry.class).in(Singleton.class); | ||
} | ||
} | ||
} |
Oops, something went wrong.