From f28fd59290b8b5d7998f0f17acfc03577b3400f6 Mon Sep 17 00:00:00 2001 From: alex-libo <569590478@qq.com> Date: Sun, 15 Apr 2018 18:21:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E6=B7=BB=E5=AF=B9AutoScanComponent?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E7=9A=84=E6=94=AF=E6=8C=81=E6=9B=B4=E5=8A=A0?= =?UTF-8?q?=E6=96=B9=E4=BE=BF=E5=8E=BB=E5=A4=84=E7=90=86=E5=92=8C=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E5=90=AF=E5=8A=A8=E6=97=B6=E5=80=99=E7=9A=84=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/hyts/app/ScanBootstrap.java | 8 +++- .../app/role/controller/RoleController.java | 44 +++++++++++++++++++ .../scan/annotation}/AutoScanComponent.java | 2 +- .../net/alex/scan/adapter/ScanAdapter.java | 24 ++++++---- .../web/component/FullScanComponent.java | 2 +- 5 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 jfmvc-application/src/main/java/com/hyts/app/role/controller/RoleController.java rename jfmvc-framework/{hyts-jfmvc-web/src/main/java/com/hyts/jfmvc/web/component => hyts-jfmvc-scan/src/main/java/com/hyts/jfmvc/scan/annotation}/AutoScanComponent.java (94%) diff --git a/jfmvc-application/src/main/java/com/hyts/app/ScanBootstrap.java b/jfmvc-application/src/main/java/com/hyts/app/ScanBootstrap.java index 81dd04c..eb22dac 100644 --- a/jfmvc-application/src/main/java/com/hyts/app/ScanBootstrap.java +++ b/jfmvc-application/src/main/java/com/hyts/app/ScanBootstrap.java @@ -14,8 +14,12 @@ */ package com.hyts.app; +import java.util.stream.Stream; + +import net.alex.scan.annotation.IncludeAnnotations; import net.alex.scan.annotation.IncludePackages; +import com.hyts.jfmvc.scan.annotation.AutoScanComponent; import com.hyts.jfmvc.web.component.FullScanComponent; /** @@ -37,6 +41,8 @@ import com.hyts.jfmvc.web.component.FullScanComponent; * @version V1.0 */ @IncludePackages(packagePaths = {"com.hyts.app"}) -public class ScanBootstrap extends FullScanComponent{ +@AutoScanComponent +public class ScanBootstrap { + } diff --git a/jfmvc-application/src/main/java/com/hyts/app/role/controller/RoleController.java b/jfmvc-application/src/main/java/com/hyts/app/role/controller/RoleController.java new file mode 100644 index 0000000..b0829b1 --- /dev/null +++ b/jfmvc-application/src/main/java/com/hyts/app/role/controller/RoleController.java @@ -0,0 +1,44 @@ +/* + * Copyright [2018] [Alex/libo(liboms@hotmail.com)] + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.hyts.app.role.controller; + +import com.hyts.jfmvc.rpc.DataService; +import com.hyts.jfmvc.scan.annotation.Controller; +import com.hyts.jfmvc.scan.annotation.Resource; +import com.hyts.jfmvc.web.controller.BaseController; + +/** + * @title RoleController.java + * @package com.hyts.app.role.controller + * @description TODO + * @see TODO + * @author libo/Alex + * @email liboms@hotmail.com/liboware@163.com + * @date 2018年4月11日 + * @version V1.0 + */ +@Controller("/role") +public class RoleController extends BaseController { + + @Resource + private DataService sevice; + + public void query() + { + sevice.test(); + System.out.println("查询用户角色操作!"); + } + +} diff --git a/jfmvc-framework/hyts-jfmvc-web/src/main/java/com/hyts/jfmvc/web/component/AutoScanComponent.java b/jfmvc-framework/hyts-jfmvc-scan/src/main/java/com/hyts/jfmvc/scan/annotation/AutoScanComponent.java similarity index 94% rename from jfmvc-framework/hyts-jfmvc-web/src/main/java/com/hyts/jfmvc/web/component/AutoScanComponent.java rename to jfmvc-framework/hyts-jfmvc-scan/src/main/java/com/hyts/jfmvc/scan/annotation/AutoScanComponent.java index 3eca8e4..65f4c02 100644 --- a/jfmvc-framework/hyts-jfmvc-web/src/main/java/com/hyts/jfmvc/web/component/AutoScanComponent.java +++ b/jfmvc-framework/hyts-jfmvc-scan/src/main/java/com/hyts/jfmvc/scan/annotation/AutoScanComponent.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.hyts.jfmvc.web.component; +package com.hyts.jfmvc.scan.annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; diff --git a/jfmvc-framework/hyts-jfmvc-scan/src/main/java/net/alex/scan/adapter/ScanAdapter.java b/jfmvc-framework/hyts-jfmvc-scan/src/main/java/net/alex/scan/adapter/ScanAdapter.java index a852773..91b02bf 100644 --- a/jfmvc-framework/hyts-jfmvc-scan/src/main/java/net/alex/scan/adapter/ScanAdapter.java +++ b/jfmvc-framework/hyts-jfmvc-scan/src/main/java/net/alex/scan/adapter/ScanAdapter.java @@ -22,6 +22,11 @@ import java.io.File; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.security.cert.PKIXRevocationChecker.Option; +import java.util.Objects; +import java.util.Optional; + +import com.hyts.jfmvc.scan.annotation.AutoScanComponent; import net.alex.scan.annotation.ExcludePackages; import net.alex.scan.annotation.FilterExtNames; @@ -95,13 +100,11 @@ public class ScanAdapter { { //校验所有相关服务启动 IncludePackages includePackages = (IncludePackages) clazz.getAnnotation(IncludePackages.class); + System.out.println(includePackages.packagePaths()[0]); String defaultClassScannerPackage = clazz.getPackage().getName(); - if(includePackages == null) - { + if(includePackages == null) { AnnotationConfig.INCLUDE_PACKAGE_NAMES = defaultClassScannerPackage; - } - else - { + }else { if(includePackages.annotationType().getDeclaredMethods() != null || includePackages.annotationType().getDeclaredMethods().length != 0){ @@ -139,12 +142,15 @@ public class ScanAdapter { } } } - Annotation includeAnnotation = clazz.getAnnotation(IncludeAnnotations.class); - if(includeAnnotation != null) - { + /** + * @author libo + * @date 2018-04-15 + * @description 修改注解扫描兼容AutoScanAnnotation注解 + */ + Annotation includeAnnotation = Objects.isNull(clazz.getAnnotation(IncludeAnnotations.class))?clazz.getAnnotation(AutoScanComponent.class).annotationType().getAnnotation(IncludeAnnotations.class):clazz.getAnnotation(IncludeAnnotations.class); + if(includeAnnotation != null) { if(includeAnnotation.annotationType().getDeclaredMethods() != null || includeAnnotation.annotationType().getDeclaredMethods().length != 0){ - Method[] methods = includeAnnotation.annotationType().getMethods(); for(Method method2:methods) { diff --git a/jfmvc-framework/hyts-jfmvc-web/src/main/java/com/hyts/jfmvc/web/component/FullScanComponent.java b/jfmvc-framework/hyts-jfmvc-web/src/main/java/com/hyts/jfmvc/web/component/FullScanComponent.java index c10fe5f..d16559c 100644 --- a/jfmvc-framework/hyts-jfmvc-web/src/main/java/com/hyts/jfmvc/web/component/FullScanComponent.java +++ b/jfmvc-framework/hyts-jfmvc-web/src/main/java/com/hyts/jfmvc/web/component/FullScanComponent.java @@ -26,7 +26,7 @@ import net.alex.scan.annotation.IncludeAnnotations; /** * @Title FullScanComponent.java * @Package com.hyts.jfmvc.web.component - * @Description 扫描系统中所有相关的服务注解-快捷类(Controlle/Service/Entity/Repository) + * @Description 扫描系统中所有相关的服务注解-快捷类(Controller/Service/Entity/Repository) * 只需要继承此类即可 * @author LiBo/Alex * @date 2017年11月6日 -- Gitee