Pārlūkot izejas kodu

增加脚本变量名

zhouhao 7 gadi atpakaļ
vecāks
revīzija
36b3eb63a3

+ 2 - 0
hsweb-core/src/main/java/org/hswebframework/web/ScriptScope.java

@@ -9,4 +9,6 @@ import java.lang.annotation.*;
 @Retention(RetentionPolicy.RUNTIME)
 @Documented
 public @interface ScriptScope {
+
+    String value() default "";
 }

+ 3 - 7
hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/SystemInitializeAutoConfiguration.java

@@ -30,9 +30,7 @@ import org.hsweb.ezorm.rdb.render.dialect.OracleRDBDatabaseMetaData;
 import org.hsweb.ezorm.rdb.simple.SimpleDatabase;
 import org.hswebframework.expands.script.engine.DynamicScriptEngine;
 import org.hswebframework.expands.script.engine.DynamicScriptEngineFactory;
-import org.hswebframework.web.AopUtils;
 import org.hswebframework.web.ScriptScope;
-import org.hswebframework.web.dao.Dao;
 import org.hswebframework.web.datasource.DataSourceHolder;
 import org.hswebframework.web.datasource.DatabaseType;
 import org.hswebframework.web.service.Service;
@@ -44,7 +42,6 @@ import org.springframework.beans.factory.config.BeanPostProcessor;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.core.Ordered;
 import org.springframework.core.annotation.AnnotationUtils;
@@ -52,10 +49,8 @@ import org.springframework.core.annotation.Order;
 import org.springframework.util.ClassUtils;
 
 import javax.annotation.PostConstruct;
-import javax.script.ScriptEngine;
 import javax.sql.DataSource;
 import java.sql.Connection;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
@@ -145,10 +140,11 @@ public class SystemInitializeAutoConfiguration implements CommandLineRunner, Bea
 
     @Override
     public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
+        ScriptScope scope;
         if (bean instanceof Service) {
             addGlobalVariable(beanName, bean);
-        } else if (AnnotationUtils.findAnnotation(ClassUtils.getUserClass(bean), ScriptScope.class) != null) {
-            addGlobalVariable(beanName, bean);
+        } else if ((scope = AnnotationUtils.findAnnotation(ClassUtils.getUserClass(bean), ScriptScope.class)) != null) {
+            addGlobalVariable(!scope.value().isEmpty() ? scope.value() : beanName, bean);
         }
         return bean;
     }

+ 1 - 2
hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/init/SystemInitialize.java

@@ -27,8 +27,6 @@ import java.util.stream.Collectors;
 import static org.hswebframework.web.starter.SystemVersion.Property.*;
 
 /**
- * TODO 完成注释
- *
  * @author zhouhao
  */
 public class SystemInitialize {
@@ -54,6 +52,7 @@ public class SystemInitialize {
         this.targetVersion = targetVersion;
         scriptContext.put("sqlExecutor", sqlExecutor);
         scriptContext.put("database", database);
+        scriptContext.put("logger", logger);
     }
 
     public void addScriptContext(String var, Object val) {