aop代码调整。

This commit is contained in:
aoshiguchen
2022-07-06 17:21:51 +08:00
parent 6657060f01
commit 88a218962b
3 changed files with 16 additions and 10 deletions
@@ -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);
}
@@ -85,6 +85,10 @@ public class ApplicationContext implements LifeCycle {
this.rootBeanFactory.registerBean(this, "rootApplicationContext");
this.rootBeanFactory.registerBean(environment.getConfig(), "rootApplicationConfig");
register();
List<BeanFactoryAware> 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<BeanFactoryAware> beanFactoryAwareList = this.applicationBeanFactory.getBeanList(BeanFactoryAware.class);
if (CollectionUtil.notEmpty(beanFactoryAwareList)) {
beanFactoryAwareList.forEach(beanFactoryAware -> beanFactoryAware.setBeanFactory(applicationBeanFactory));
}
List<ApplicationRunner> applicationRunnerList = this.applicationBeanFactory.getBeanList(ApplicationRunner.class);
if (CollectionUtil.notEmpty(applicationRunnerList)) {
applicationRunnerList.forEach(applicationRunner -> applicationRunner.run(this.environment.getMainArgs()));
@@ -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<Method, Params> paramsCache = new MemoryCache<>();
@Init
public void a() {
System.out.println("11");
}
@Override
public void intercept(Invocation inv) throws Exception {
Assert.notNull(jdbcTemplate, "JdbcTemplate未注入,调用失败!");