1. 程式人生 > 遊戲攻略 >《原神攻略》npc賀摩在哪裡?2.4淵下宮npc賀摩位置分享

《原神攻略》npc賀摩在哪裡?2.4淵下宮npc賀摩位置分享

1:往ioc中新增一個物件:裡面在初始化MyBean的時候需要引數,而這個引數卻 配置在properties檔案中,就可以寫成下面這樣

@PropertySource表示讀取配置檔案

 @Configuration
 @PropertySource("classpath:/com/acme/app.properties")
 public class AppConfig {

     @Inject Environment env;

     @Bean
     public MyBean myBean() {
         return new MyBean(env.getProperty("bean.name"));
     }
 }

測試呼叫

 AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
 ctx.register(AppConfig.class);
 ctx.refresh();
 MyBean myBean = ctx.getBean(MyBean.class);
 // use myBean ...

@Profile(""):表示當前需要使用哪個配置檔案中的資料,有開發版,釋出版。

 @Configuration
 public class ProfileDatabaseConfig {

     @Bean(
"dataSource") @Profile("development") public DataSource embeddedDatabase() { ... } @Bean("dataSource") @Profile("production") public DataSource productionDatabase() { ... } }