Commit 2fb15e19 authored by 张永's avatar 张永

1

parent 87469c5d
package com.egolm.shop; package com.egolm.shop;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableCaching @EnableCaching
@EnableSwagger2 @EnableSwagger2
@SpringBootApplication @SpringBootApplication
@EnableTransactionManagement @EnableTransactionManagement
public class ShopApplication { public class ShopApplication {
private static ApplicationContext applicationContext; private static ApplicationContext applicationContext;
public static void main(String[] args) { public static void main(String[] args) {
applicationContext = SpringApplication.run(ShopApplication.class, args); applicationContext = SpringApplication.run(ShopApplication.class, args);
} }
public static ApplicationContext getApplicationContext() { public static ApplicationContext getApplicationContext() {
return applicationContext; return applicationContext;
} }
public static Object getBean(String name){ public static Object getBean(String name){
return getApplicationContext().getBean(name); return getApplicationContext().getBean(name);
} }
public static <T> T getBean(Class<T> clazz){ public static <T> T getBean(Class<T> clazz){
return getApplicationContext().getBean(clazz); return getApplicationContext().getBean(clazz);
} }
public static <T> T getBean(String name, Class<T> clazz){ public static <T> T getBean(String name, Class<T> clazz){
return getApplicationContext().getBean(name, clazz); return getApplicationContext().getBean(name, clazz);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment