This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 169
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
6 changed files
with
56 additions
and
88 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
85 changes: 32 additions & 53 deletions
85
SPR-9756/src/main/java/org/springsource/investigation/App.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,68 +1,47 @@ | ||
package org.springsource.investigation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.context.annotation.PropertySource; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Service; | ||
|
||
abstract class BaseConfig { | ||
|
||
@Autowired | ||
protected Environment environment; | ||
|
||
@Bean | ||
public AppIdStringWrapper connectionFactoryLocator() | ||
{ | ||
return new AppIdStringWrapper(environment.getProperty("appId")); | ||
} | ||
} | ||
|
||
class AppIdStringWrapper { | ||
private String profileName; | ||
|
||
public AppIdStringWrapper(String profileName) { | ||
this.profileName = profileName; | ||
} | ||
|
||
public String getProfileName() { | ||
return this.profileName; | ||
} | ||
} | ||
|
||
|
||
@Profile("prod") | ||
@Configuration | ||
@PropertySource({ "classpath:prod-app.properties" }) | ||
class ProdConfig extends BaseConfig { | ||
} | ||
|
||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Profile("dev") | ||
@interface Dev { | ||
} | ||
|
||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Profile("prod") | ||
@interface Prod { | ||
} | ||
|
||
@Service | ||
public class App { | ||
|
||
@Autowired | ||
AppIdStringWrapper appIdStringWrapper; | ||
|
||
public void testApp() | ||
{ | ||
} | ||
@Autowired | ||
protected Environment environment; | ||
|
||
@Autowired | ||
protected ConfigurableApplicationContext context; | ||
|
||
@Bean | ||
public String foo() { | ||
this.environment.getProperty("appId"); | ||
//assertThat(this.context.getEnvironment(), sameInstance(this.environment)); | ||
System.out.println("testing this.environment"); | ||
test(this.environment); | ||
System.out.println("testing this.context.getBF().getBean(Env.class)"); | ||
test((Environment)this.context.getBeanFactory().getBean("environment")); | ||
System.out.println("testing this.context.getEnv()"); | ||
test(this.context.getEnvironment()); | ||
return "bogus"; | ||
} | ||
|
||
private void test(Environment env) { | ||
if (this.context.getEnvironment() == env) { | ||
System.out.println("environment belongs to autowired app context"); | ||
} | ||
else if (this.context.getParent().getEnvironment() == env){ | ||
System.out.println("environment belongs to PARENT OF autowired app context"); | ||
} | ||
else { | ||
System.out.println("environment is of unknown origin"); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
#### Credentials ### | ||
appId=prod |
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