diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java index abd14493..c908cc7b 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java @@ -61,12 +61,12 @@ public class InterceptorFactory { () -> { try { // TODO - cache.set(clazz, clazz.newInstance()); -// if (BeanManager.getBean(clazz) != null) { -// cache.set(clazz, BeanManager.getBean(clazz)); -// } else { -// cache.set(clazz, clazz.newInstance()); -// } +// cache.set(clazz, clazz.newInstance()); + if (BeanManager.getBean(clazz) != null) { + cache.set(clazz, BeanManager.getBean(clazz)); + } else { + cache.set(clazz, clazz.newInstance()); + } } catch (InstantiationException|IllegalAccessException e) { throw new RuntimeException(e); } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/context/ApplicationContext.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/context/ApplicationContext.java index de55e915..36e6fa0c 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/context/ApplicationContext.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/context/ApplicationContext.java @@ -85,6 +85,10 @@ public class ApplicationContext implements LifeCycle { this.rootBeanFactory.registerBean(this, "rootApplicationContext"); this.rootBeanFactory.registerBean(environment.getConfig(), "rootApplicationConfig"); register(); + List beanFactoryAwareList = this.applicationBeanFactory.getBeanList(BeanFactoryAware.class); + if (CollectionUtil.notEmpty(beanFactoryAwareList)) { + beanFactoryAwareList.forEach(beanFactoryAware -> beanFactoryAware.setBeanFactory(applicationBeanFactory)); + } this.applicationBeanFactory.init(); } catch (Exception e) { log.error("应用上下文初始化异常!", e); @@ -138,10 +142,6 @@ public class ApplicationContext implements LifeCycle { */ public void run() { init(); - List beanFactoryAwareList = this.applicationBeanFactory.getBeanList(BeanFactoryAware.class); - if (CollectionUtil.notEmpty(beanFactoryAwareList)) { - beanFactoryAwareList.forEach(beanFactoryAware -> beanFactoryAware.setBeanFactory(applicationBeanFactory)); - } List applicationRunnerList = this.applicationBeanFactory.getBeanList(ApplicationRunner.class); if (CollectionUtil.notEmpty(applicationRunnerList)) { applicationRunnerList.forEach(applicationRunner -> applicationRunner.run(this.environment.getMainArgs())); diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java index ba03488b..a86dbdf8 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java @@ -23,6 +23,7 @@ package fun.asgc.neutrino.core.db.mapper; import fun.asgc.neutrino.core.annotation.Autowired; import fun.asgc.neutrino.core.annotation.Component; +import fun.asgc.neutrino.core.annotation.Init; import fun.asgc.neutrino.core.annotation.NonIntercept; import fun.asgc.neutrino.core.aop.Invocation; import fun.asgc.neutrino.core.aop.interceptor.Interceptor; @@ -52,6 +53,11 @@ public class SqlMapperInterceptor implements Interceptor { private JdbcTemplate jdbcTemplate; private static final Cache paramsCache = new MemoryCache<>(); + @Init + public void a() { + System.out.println("11"); + } + @Override public void intercept(Invocation inv) throws Exception { Assert.notNull(jdbcTemplate, "JdbcTemplate未注入,调用失败!");