From b24f09407cba2a3c11b6fbaee7a087943a5f4f05 Mon Sep 17 00:00:00 2001 From: LambdaExpression <13425088053@139.com> Date: Tue, 19 Sep 2017 14:31:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=20=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- makeGif/pom.xml | 57 ----- pom.xml | 216 +++++++++--------- src/main/java/org/pqh/aop/MatcherRule.java | 11 - src/main/webapp/WEB-INF/jsp/index.jsp | 10 - src/test/java/JunitTest.java | 48 ---- webCrawler-achieve/pom.xml | 95 ++++++++ .../achieve}/config/AbstractWebConfig.java | 2 +- .../org/pqh/achieve}/config/SpringConfig.java | 3 +- .../pqh/achieve}/config/WebConfigImpl.java | 2 +- .../pqh/achieve/config/WebCrawlerConfig.java | 9 + .../achieve}/controller/AdminController.java | 2 +- .../achieve}/controller/BaseController.java | 16 +- .../achieve}/controller/ConfigController.java | 4 +- .../achieve}/controller/ParamController.java | 4 +- .../src/main/resources/config.properties | 6 + .../src}/main/resources/log4j2.xml | 0 .../src/main/webapp/WEB-INF/jsp/index.jsp | 5 + webCrawler-core/pom.xml | 91 ++++++++ .../EnableWebCrawlerConfiguration.java | 17 ++ .../java/org/pqh/core}/aop/InsertAdvice.java | 4 +- .../java/org/pqh/core}/aop/InsertAdvisor.java | 4 +- .../java/org/pqh/core}/aop/LogAspect.java | 10 +- .../java/org/pqh/core/aop/MatcherRule.java | 12 + .../org/pqh/core}/config/HibernateConfig.java | 31 +-- .../main/java/org/pqh/core}/dao/BaseDao.java | 16 +- .../org/pqh/core}/model/AbstractModel.java | 2 +- .../main/java/org/pqh/core}/model/Config.java | 2 +- .../main/java/org/pqh/core}/model/Param.java | 2 +- .../org/pqh/core}/service/BaseService.java | 23 +- .../java/org/pqh/core}/util/DBAction.java | 2 +- .../org/pqh/core/util/PropertiesUtil.java | 47 ++++ 31 files changed, 458 insertions(+), 295 deletions(-) delete mode 100644 makeGif/pom.xml delete mode 100644 src/main/java/org/pqh/aop/MatcherRule.java delete mode 100644 src/main/webapp/WEB-INF/jsp/index.jsp delete mode 100644 src/test/java/JunitTest.java create mode 100644 webCrawler-achieve/pom.xml rename {src/main/java/org/pqh => webCrawler-achieve/src/main/java/org/pqh/achieve}/config/AbstractWebConfig.java (97%) rename {src/main/java/org/pqh => webCrawler-achieve/src/main/java/org/pqh/achieve}/config/SpringConfig.java (94%) rename {src/main/java/org/pqh => webCrawler-achieve/src/main/java/org/pqh/achieve}/config/WebConfigImpl.java (97%) create mode 100644 webCrawler-achieve/src/main/java/org/pqh/achieve/config/WebCrawlerConfig.java rename {src/main/java/org/pqh => webCrawler-achieve/src/main/java/org/pqh/achieve}/controller/AdminController.java (91%) rename {src/main/java/org/pqh => webCrawler-achieve/src/main/java/org/pqh/achieve}/controller/BaseController.java (58%) rename {src/main/java/org/pqh => webCrawler-achieve/src/main/java/org/pqh/achieve}/controller/ConfigController.java (78%) rename {src/main/java/org/pqh => webCrawler-achieve/src/main/java/org/pqh/achieve}/controller/ParamController.java (78%) create mode 100644 webCrawler-achieve/src/main/resources/config.properties rename {src => webCrawler-achieve/src}/main/resources/log4j2.xml (100%) create mode 100644 webCrawler-achieve/src/main/webapp/WEB-INF/jsp/index.jsp create mode 100644 webCrawler-core/pom.xml create mode 100644 webCrawler-core/src/main/java/org/pqh/core/annotation/EnableWebCrawlerConfiguration.java rename {src/main/java/org/pqh => webCrawler-core/src/main/java/org/pqh/core}/aop/InsertAdvice.java (65%) rename {src/main/java/org/pqh => webCrawler-core/src/main/java/org/pqh/core}/aop/InsertAdvisor.java (87%) rename {src/main/java/org/pqh => webCrawler-core/src/main/java/org/pqh/core}/aop/LogAspect.java (53%) create mode 100644 webCrawler-core/src/main/java/org/pqh/core/aop/MatcherRule.java rename {src/main/java/org/pqh => webCrawler-core/src/main/java/org/pqh/core}/config/HibernateConfig.java (64%) rename {src/main/java/org/pqh => webCrawler-core/src/main/java/org/pqh/core}/dao/BaseDao.java (54%) rename {src/main/java/org/pqh => webCrawler-core/src/main/java/org/pqh/core}/model/AbstractModel.java (87%) rename {src/main/java/org/pqh => webCrawler-core/src/main/java/org/pqh/core}/model/Config.java (97%) rename {src/main/java/org/pqh => webCrawler-core/src/main/java/org/pqh/core}/model/Param.java (98%) rename {src/main/java/org/pqh => webCrawler-core/src/main/java/org/pqh/core}/service/BaseService.java (61%) rename {src/main/java/org/pqh => webCrawler-core/src/main/java/org/pqh/core}/util/DBAction.java (80%) create mode 100644 webCrawler-core/src/main/java/org/pqh/core/util/PropertiesUtil.java diff --git a/makeGif/pom.xml b/makeGif/pom.xml deleted file mode 100644 index 76fd72f..0000000 --- a/makeGif/pom.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - webCrawler - org.pqh - 1.0 - - 4.0.0 - - makeGif - - - - makeGif - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.1 - - ${java.version} - ${java.version} - UTF-8 - - - - - maven-assembly-plugin - - - jar-with-dependencies - - - - - - - - - - make-assembly - package - - single - - - - - - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 80f4cb7..cf4fdce 100644 --- a/pom.xml +++ b/pom.xml @@ -1,124 +1,131 @@ - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 - org.pqh webCrawler - war - 1.0 - - 简单的网络爬虫客户端 + pom + 1.0-SNAPSHOT - makeGif + webCrawler-core + webCrawler-achieve + webCrawler Maven Webapp + https://gitee.com/WuXianChaoPin/webCrawler UTF-8 UTF-8 1.8 + + 4.3.10.RELEASE 6.0.6 - RELEASE + 2.1.1 + 5.2.10.Final + 2.9.0 + 1.8.10 + 2.8.2 + 2.5 + 4.12 + 3.1.0 - - - - org.springframework - spring-web - ${spring.version} - - - - org.springframework - spring-webmvc - ${spring.version} - - - - org.springframework - spring-orm - ${spring.version} - - - - org.apache.commons - commons-dbcp2 - LATEST - - - org.hibernate - hibernate-core - RELEASE - - - - mysql - mysql-connector-java - ${mysql.version} - - - - com.fasterxml.jackson.core - jackson-databind - LATEST - - - - org.aspectj - aspectjweaver - LATEST - - - - org.apache.logging.log4j - log4j-api - LATEST - - - - org.apache.logging.log4j - log4j-core - LATEST - - - - org.apache.logging.log4j - log4j-web - LATEST - - - - - - - - - - commons-io - commons-io - LATEST - - - - javax.servlet - javax.servlet-api - 3.1.0 - provided - - - - - - - - + + + + + org.springframework + spring-web + ${spring.version} + + + + org.springframework + spring-webmvc + ${spring.version} + + + + org.springframework + spring-orm + ${spring.version} + + + + org.apache.commons + commons-dbcp2 + ${commons-dbcp2.version} + + + org.hibernate + hibernate-core + ${hibernate-core.version} + + + + mysql + mysql-connector-java + ${mysql.version} + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind.version} + + + + org.aspectj + aspectjweaver + ${aspectjweaver.version} + + + + org.apache.logging.log4j + log4j-api + ${log4j.version} + + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + + + + org.apache.logging.log4j + log4j-web + ${log4j.version} + + + + commons-io + commons-io + ${commons-io.version} + + + + javax.servlet + javax.servlet-api + ${servlet-api.version} + provided + + + + junit + junit + ${junit.version} + test + + + - webCrawler - + + maven-war-plugin + 3.0.0 + org.apache.maven.plugins maven-compiler-plugin @@ -131,7 +138,4 @@ - - - diff --git a/src/main/java/org/pqh/aop/MatcherRule.java b/src/main/java/org/pqh/aop/MatcherRule.java deleted file mode 100644 index ecce2be..0000000 --- a/src/main/java/org/pqh/aop/MatcherRule.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.pqh.aop; - -import org.aspectj.lang.annotation.Pointcut; - -/** - * Created by reborn on 2017/8/3. - */ -public class MatcherRule { - @Pointcut("execution(* org.pqh.dao.BaseDao.*(..))") - public void biliDaoRule(){} -} diff --git a/src/main/webapp/WEB-INF/jsp/index.jsp b/src/main/webapp/WEB-INF/jsp/index.jsp deleted file mode 100644 index 77cdad8..0000000 --- a/src/main/webapp/WEB-INF/jsp/index.jsp +++ /dev/null @@ -1,10 +0,0 @@ -<%@ page contentType="text/html;charset=UTF-8" language="java" %> - - - - Title - - -

首页

- - \ No newline at end of file diff --git a/src/test/java/JunitTest.java b/src/test/java/JunitTest.java deleted file mode 100644 index 300ca76..0000000 --- a/src/test/java/JunitTest.java +++ /dev/null @@ -1,48 +0,0 @@ -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.core.config.xml.XmlConfiguration; - -import java.net.URI; -import java.net.URISyntaxException; - -/** - * Created by reborn on 2017/8/3. - */ - -public class JunitTest { - -// private static final boolean flag=init(); - private static final Logger rootLogger= LogManager.getLogger(); - private static final Logger consoleLogger= LogManager.getLogger("log1"); - private static final Logger loggerFile= LogManager.getLogger("log2"); - - public static void main(String[] args) { - -// rootLogger.info("rootLogger"); -// consoleLogger.info("consoleLogger"); -// loggerFile.info("loggerFile"); - -// Collection loggers=loggerContext.getLoggers(); -// for(org.apache.logging.log4j.core.Logger logger:loggers){ -// logger.info(logger.getName()); -// } - - - } - - - - private static boolean init(){ - System.out.println(XmlConfiguration.class.getClassLoader()); - LoggerContext loggerContext= (LoggerContext) LogManager.getContext(false); - try { - URI uri=new URI("http://42.56.70.185:8080/master/testlog.xml"); - loggerContext.setConfigLocation(uri); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - return true; - } - -} diff --git a/webCrawler-achieve/pom.xml b/webCrawler-achieve/pom.xml new file mode 100644 index 0000000..a558249 --- /dev/null +++ b/webCrawler-achieve/pom.xml @@ -0,0 +1,95 @@ + + + webCrawler + org.pqh + 1.0-SNAPSHOT + + 4.0.0 + achieve + war + achieve Maven Webapp + https://gitee.com/WuXianChaoPin/webCrawler + + + org.pqh + core + 1.0-SNAPSHOT + + + + org.springframework + spring-web + + + + org.springframework + spring-webmvc + + + + org.springframework + spring-orm + + + + org.apache.commons + commons-dbcp2 + + + + org.hibernate + hibernate-core + + + + mysql + mysql-connector-java + + + + com.fasterxml.jackson.core + jackson-databind + + + + org.aspectj + aspectjweaver + + + + org.apache.logging.log4j + log4j-api + + + + org.apache.logging.log4j + log4j-core + + + + org.apache.logging.log4j + log4j-web + + + + commons-io + commons-io + + + + javax.servlet + javax.servlet-api + provided + + + + junit + junit + test + + + + achieve + + diff --git a/src/main/java/org/pqh/config/AbstractWebConfig.java b/webCrawler-achieve/src/main/java/org/pqh/achieve/config/AbstractWebConfig.java similarity index 97% rename from src/main/java/org/pqh/config/AbstractWebConfig.java rename to webCrawler-achieve/src/main/java/org/pqh/achieve/config/AbstractWebConfig.java index 41a153b..66c1f68 100644 --- a/src/main/java/org/pqh/config/AbstractWebConfig.java +++ b/webCrawler-achieve/src/main/java/org/pqh/achieve/config/AbstractWebConfig.java @@ -1,4 +1,4 @@ -package org.pqh.config; +package org.pqh.achieve.config; import org.apache.logging.log4j.LogManager; import org.springframework.web.filter.CharacterEncodingFilter; diff --git a/src/main/java/org/pqh/config/SpringConfig.java b/webCrawler-achieve/src/main/java/org/pqh/achieve/config/SpringConfig.java similarity index 94% rename from src/main/java/org/pqh/config/SpringConfig.java rename to webCrawler-achieve/src/main/java/org/pqh/achieve/config/SpringConfig.java index 2d9eedd..e953d17 100644 --- a/src/main/java/org/pqh/config/SpringConfig.java +++ b/webCrawler-achieve/src/main/java/org/pqh/achieve/config/SpringConfig.java @@ -1,5 +1,6 @@ -package org.pqh.config; +package org.pqh.achieve.config; +import org.pqh.core.config.HibernateConfig; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.*; import org.springframework.web.servlet.config.annotation.EnableWebMvc; diff --git a/src/main/java/org/pqh/config/WebConfigImpl.java b/webCrawler-achieve/src/main/java/org/pqh/achieve/config/WebConfigImpl.java similarity index 97% rename from src/main/java/org/pqh/config/WebConfigImpl.java rename to webCrawler-achieve/src/main/java/org/pqh/achieve/config/WebConfigImpl.java index 1bf04f8..60dfc44 100644 --- a/src/main/java/org/pqh/config/WebConfigImpl.java +++ b/webCrawler-achieve/src/main/java/org/pqh/achieve/config/WebConfigImpl.java @@ -1,4 +1,4 @@ -package org.pqh.config; +package org.pqh.achieve.config; import org.apache.logging.log4j.LogManager; import org.springframework.web.WebApplicationInitializer; diff --git a/webCrawler-achieve/src/main/java/org/pqh/achieve/config/WebCrawlerConfig.java b/webCrawler-achieve/src/main/java/org/pqh/achieve/config/WebCrawlerConfig.java new file mode 100644 index 0000000..700147e --- /dev/null +++ b/webCrawler-achieve/src/main/java/org/pqh/achieve/config/WebCrawlerConfig.java @@ -0,0 +1,9 @@ +package org.pqh.achieve.config; + +import org.pqh.core.annotation.EnableWebCrawlerConfiguration; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableWebCrawlerConfiguration +public class WebCrawlerConfig { +} diff --git a/src/main/java/org/pqh/controller/AdminController.java b/webCrawler-achieve/src/main/java/org/pqh/achieve/controller/AdminController.java similarity index 91% rename from src/main/java/org/pqh/controller/AdminController.java rename to webCrawler-achieve/src/main/java/org/pqh/achieve/controller/AdminController.java index 2d3fc27..0cd0d62 100644 --- a/src/main/java/org/pqh/controller/AdminController.java +++ b/webCrawler-achieve/src/main/java/org/pqh/achieve/controller/AdminController.java @@ -1,4 +1,4 @@ -package org.pqh.controller; +package org.pqh.achieve.controller; import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Controller; diff --git a/src/main/java/org/pqh/controller/BaseController.java b/webCrawler-achieve/src/main/java/org/pqh/achieve/controller/BaseController.java similarity index 58% rename from src/main/java/org/pqh/controller/BaseController.java rename to webCrawler-achieve/src/main/java/org/pqh/achieve/controller/BaseController.java index 3b401f2..864d980 100644 --- a/src/main/java/org/pqh/controller/BaseController.java +++ b/webCrawler-achieve/src/main/java/org/pqh/achieve/controller/BaseController.java @@ -1,10 +1,10 @@ -package org.pqh.controller; +package org.pqh.achieve.controller; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.pqh.model.AbstractModel; -import org.pqh.service.BaseService; -import org.pqh.util.DBAction; +import org.pqh.core.model.AbstractModel; +import org.pqh.core.service.BaseService; +import org.pqh.core.util.DBAction; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -18,15 +18,15 @@ import javax.annotation.Resource; @Controller public class BaseController { - protected Logger log= LogManager.getLogger(); + protected Logger log = LogManager.getLogger(); @Resource protected BaseService baseService; @ResponseBody - @RequestMapping(value = "{action}",produces = "text/html;charset=UTF-8") - public String curd(@PathVariable DBAction action,T model) { - log.info(model.tableNote()+"进行"+action+"操作请求"); + @RequestMapping(value = "{action}", produces = "text/html;charset=UTF-8") + public String curd(@PathVariable DBAction action, T model) { + log.info(model.tableNote() + "进行" + action + "操作请求"); return baseService.curd(action, model); } diff --git a/src/main/java/org/pqh/controller/ConfigController.java b/webCrawler-achieve/src/main/java/org/pqh/achieve/controller/ConfigController.java similarity index 78% rename from src/main/java/org/pqh/controller/ConfigController.java rename to webCrawler-achieve/src/main/java/org/pqh/achieve/controller/ConfigController.java index 6ac3c13..27d755b 100644 --- a/src/main/java/org/pqh/controller/ConfigController.java +++ b/webCrawler-achieve/src/main/java/org/pqh/achieve/controller/ConfigController.java @@ -1,6 +1,6 @@ -package org.pqh.controller; +package org.pqh.achieve.controller; -import org.pqh.model.Config; +import org.pqh.core.model.Config; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/src/main/java/org/pqh/controller/ParamController.java b/webCrawler-achieve/src/main/java/org/pqh/achieve/controller/ParamController.java similarity index 78% rename from src/main/java/org/pqh/controller/ParamController.java rename to webCrawler-achieve/src/main/java/org/pqh/achieve/controller/ParamController.java index 4c184b8..357cdd4 100644 --- a/src/main/java/org/pqh/controller/ParamController.java +++ b/webCrawler-achieve/src/main/java/org/pqh/achieve/controller/ParamController.java @@ -1,6 +1,6 @@ -package org.pqh.controller; +package org.pqh.achieve.controller; -import org.pqh.model.Param; +import org.pqh.core.model.Param; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/webCrawler-achieve/src/main/resources/config.properties b/webCrawler-achieve/src/main/resources/config.properties new file mode 100644 index 0000000..078e3ae --- /dev/null +++ b/webCrawler-achieve/src/main/resources/config.properties @@ -0,0 +1,6 @@ +#dbcp2.url=jdbc:mysql://localhost:3306/bilibili?serverTimezone=UTC&&useSSL=true +#dbcp2.username=root +#dbcp2.password=123456 +dbcp2.url=jdbc:mysql://172.16.0.50:3306/bb?serverTimezone=UTC&&useSSL=true +dbcp2.username=root +dbcp2.password=123456 \ No newline at end of file diff --git a/src/main/resources/log4j2.xml b/webCrawler-achieve/src/main/resources/log4j2.xml similarity index 100% rename from src/main/resources/log4j2.xml rename to webCrawler-achieve/src/main/resources/log4j2.xml diff --git a/webCrawler-achieve/src/main/webapp/WEB-INF/jsp/index.jsp b/webCrawler-achieve/src/main/webapp/WEB-INF/jsp/index.jsp new file mode 100644 index 0000000..c38169b --- /dev/null +++ b/webCrawler-achieve/src/main/webapp/WEB-INF/jsp/index.jsp @@ -0,0 +1,5 @@ + + +

Hello World!

+ + diff --git a/webCrawler-core/pom.xml b/webCrawler-core/pom.xml new file mode 100644 index 0000000..3629462 --- /dev/null +++ b/webCrawler-core/pom.xml @@ -0,0 +1,91 @@ + + + webCrawler + org.pqh + 1.0-SNAPSHOT + + 4.0.0 + core + jar + core Maven Webapp + https://gitee.com/WuXianChaoPin/webCrawler + + + + + org.springframework + spring-web + + + + org.springframework + spring-webmvc + + + + org.springframework + spring-orm + + + + org.apache.commons + commons-dbcp2 + + + + org.hibernate + hibernate-core + + + + mysql + mysql-connector-java + + + + com.fasterxml.jackson.core + jackson-databind + + + + org.aspectj + aspectjweaver + + + + org.apache.logging.log4j + log4j-api + + + + org.apache.logging.log4j + log4j-core + + + + org.apache.logging.log4j + log4j-web + + + + commons-io + commons-io + + + + javax.servlet + javax.servlet-api + provided + + + + junit + junit + test + + + + core + + diff --git a/webCrawler-core/src/main/java/org/pqh/core/annotation/EnableWebCrawlerConfiguration.java b/webCrawler-core/src/main/java/org/pqh/core/annotation/EnableWebCrawlerConfiguration.java new file mode 100644 index 0000000..d4297a0 --- /dev/null +++ b/webCrawler-core/src/main/java/org/pqh/core/annotation/EnableWebCrawlerConfiguration.java @@ -0,0 +1,17 @@ +package org.pqh.core.annotation; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import java.lang.annotation.*; + +/** + * 爬虫注入组件 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE}) +@Documented +@Configuration +@ComponentScan("org.pqh.core.*") +public @interface EnableWebCrawlerConfiguration { +} diff --git a/src/main/java/org/pqh/aop/InsertAdvice.java b/webCrawler-core/src/main/java/org/pqh/core/aop/InsertAdvice.java similarity index 65% rename from src/main/java/org/pqh/aop/InsertAdvice.java rename to webCrawler-core/src/main/java/org/pqh/core/aop/InsertAdvice.java index 4ec3ac2..e7092a8 100644 --- a/src/main/java/org/pqh/aop/InsertAdvice.java +++ b/webCrawler-core/src/main/java/org/pqh/core/aop/InsertAdvice.java @@ -1,4 +1,4 @@ -package org.pqh.aop; +package org.pqh.core.aop; import org.springframework.aop.MethodBeforeAdvice; @@ -12,6 +12,6 @@ public class InsertAdvice implements MethodBeforeAdvice { @Override public void before(Method method, Object[] objects, Object o) throws Throwable { - System.out.println("类:"+o.getClass()+",方法:"+method.getName()+"被调用,传入参数:"+ Arrays.asList(objects)); + System.out.println("类:" + o.getClass() + ",方法:" + method.getName() + "被调用,传入参数:" + Arrays.asList(objects)); } } diff --git a/src/main/java/org/pqh/aop/InsertAdvisor.java b/webCrawler-core/src/main/java/org/pqh/core/aop/InsertAdvisor.java similarity index 87% rename from src/main/java/org/pqh/aop/InsertAdvisor.java rename to webCrawler-core/src/main/java/org/pqh/core/aop/InsertAdvisor.java index 9c0a8b7..cb2b662 100644 --- a/src/main/java/org/pqh/aop/InsertAdvisor.java +++ b/webCrawler-core/src/main/java/org/pqh/core/aop/InsertAdvisor.java @@ -1,6 +1,6 @@ -package org.pqh.aop; +package org.pqh.core.aop; -import org.pqh.dao.BaseDao; +import org.pqh.core.dao.BaseDao; import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor; import java.lang.reflect.Method; diff --git a/src/main/java/org/pqh/aop/LogAspect.java b/webCrawler-core/src/main/java/org/pqh/core/aop/LogAspect.java similarity index 53% rename from src/main/java/org/pqh/aop/LogAspect.java rename to webCrawler-core/src/main/java/org/pqh/core/aop/LogAspect.java index 0b4647d..f1e169a 100644 --- a/src/main/java/org/pqh/aop/LogAspect.java +++ b/webCrawler-core/src/main/java/org/pqh/core/aop/LogAspect.java @@ -1,4 +1,4 @@ -package org.pqh.aop; +package org.pqh.core.aop; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; @@ -12,10 +12,10 @@ import org.springframework.stereotype.Component; @Component public class LogAspect { - @Before(value = "org.pqh.aop.MatcherRule.biliDaoRule()") - public void curdCallAction(JoinPoint joinPoint){ - for(Object arg:joinPoint.getArgs()){ - System.out.println("参数"+arg); + @Before(value = "org.pqh.core.aop.MatcherRule.biliDaoRule()") + public void curdCallAction(JoinPoint joinPoint) { + for (Object arg : joinPoint.getArgs()) { + System.out.println("参数" + arg); } } diff --git a/webCrawler-core/src/main/java/org/pqh/core/aop/MatcherRule.java b/webCrawler-core/src/main/java/org/pqh/core/aop/MatcherRule.java new file mode 100644 index 0000000..3d26e45 --- /dev/null +++ b/webCrawler-core/src/main/java/org/pqh/core/aop/MatcherRule.java @@ -0,0 +1,12 @@ +package org.pqh.core.aop; + +import org.aspectj.lang.annotation.Pointcut; + +/** + * Created by reborn on 2017/8/3. + */ +public class MatcherRule { + @Pointcut("execution(* org.pqh.core.dao.BaseDao.*(..))") + public void biliDaoRule() { + } +} diff --git a/src/main/java/org/pqh/config/HibernateConfig.java b/webCrawler-core/src/main/java/org/pqh/core/config/HibernateConfig.java similarity index 64% rename from src/main/java/org/pqh/config/HibernateConfig.java rename to webCrawler-core/src/main/java/org/pqh/core/config/HibernateConfig.java index e20ba06..5a31c4d 100644 --- a/src/main/java/org/pqh/config/HibernateConfig.java +++ b/webCrawler-core/src/main/java/org/pqh/core/config/HibernateConfig.java @@ -1,6 +1,7 @@ -package org.pqh.config; +package org.pqh.core.config; import org.apache.commons.dbcp2.BasicDataSource; +import org.pqh.core.util.PropertiesUtil; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.orm.hibernate5.HibernateTemplate; @@ -20,19 +21,21 @@ public class HibernateConfig { private LocalSessionFactoryBean sessionFactoryBean; private BasicDataSource dataSource; + Properties properties = PropertiesUtil.loadPropertiesFromResourceFile("config.properties"); public HibernateConfig() { - dataSource=new BasicDataSource(); - dataSource.setUrl("jdbc:mysql://localhost:3306/bilibili?serverTimezone=UTC&&useSSL=true"); + dataSource = new BasicDataSource(); + dataSource.setUrl(properties.getProperty("dbcp2.url")); + dataSource.setUsername(properties.getProperty("dbcp2.username")); + dataSource.setPassword(properties.getProperty("dbcp2.password")); + dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); - dataSource.setUsername("root"); - dataSource.setPassword("123456"); sessionFactoryBean = new LocalSessionFactoryBean(); sessionFactoryBean.setDataSource(dataSource); - Properties properties=new Properties(); - properties.setProperty("hibernate.connection.pool_size","5"); - properties.setProperty("hibernate.jdbc.fetch_size","50"); - properties.setProperty("hibernate.dialect","org.hibernate.dialect.MySQL57Dialect"); + Properties properties = new Properties(); + properties.setProperty("hibernate.connection.pool_size", "5"); + properties.setProperty("hibernate.jdbc.fetch_size", "50"); + properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL57Dialect"); sessionFactoryBean.setHibernateProperties(properties); sessionFactoryBean.setPackagesToScan("org.pqh.model"); try { @@ -43,15 +46,15 @@ public class HibernateConfig { } @Bean("transactionManager") - public HibernateTransactionManager hibernateTransactionManager(){ - HibernateTransactionManager hibernateTransactionManager=new HibernateTransactionManager(); + public HibernateTransactionManager hibernateTransactionManager() { + HibernateTransactionManager hibernateTransactionManager = new HibernateTransactionManager(); hibernateTransactionManager.setSessionFactory(this.sessionFactoryBean.getObject()); return hibernateTransactionManager; } - @Bean(name="hibernateTemplate") - public HibernateTemplate hibernateTemplate(){ - HibernateTemplate hibernateTemplate=new HibernateTemplate(); + @Bean(name = "hibernateTemplate") + public HibernateTemplate hibernateTemplate() { + HibernateTemplate hibernateTemplate = new HibernateTemplate(); hibernateTemplate.setSessionFactory(sessionFactoryBean.getObject()); return hibernateTemplate; } diff --git a/src/main/java/org/pqh/dao/BaseDao.java b/webCrawler-core/src/main/java/org/pqh/core/dao/BaseDao.java similarity index 54% rename from src/main/java/org/pqh/dao/BaseDao.java rename to webCrawler-core/src/main/java/org/pqh/core/dao/BaseDao.java index 1a3d860..01f1dee 100644 --- a/src/main/java/org/pqh/dao/BaseDao.java +++ b/webCrawler-core/src/main/java/org/pqh/core/dao/BaseDao.java @@ -1,6 +1,6 @@ -package org.pqh.dao; +package org.pqh.core.dao; -import org.pqh.model.AbstractModel; +import org.pqh.core.model.AbstractModel; import org.springframework.dao.DataAccessException; import org.springframework.orm.hibernate5.HibernateTemplate; import org.springframework.stereotype.Repository; @@ -18,17 +18,17 @@ public class BaseDao { @Resource private HibernateTemplate hibernateTemplate; - public T get(Class T, Serializable pk) throws DataAccessException{ - return hibernateTemplate.get(T,pk); + public T get(Class T, Serializable pk) throws DataAccessException { + return hibernateTemplate.get(T, pk); } - public void saveOrUpdate(T model)throws DataAccessException{ + public void saveOrUpdate(T model) throws DataAccessException { hibernateTemplate.saveOrUpdate(model); } - public void delete(Class T,Serializable key) throws DataAccessException { - T model= get(T,key); - if(model!=null){ + public void delete(Class T, Serializable key) throws DataAccessException { + T model = get(T, key); + if (model != null) { hibernateTemplate.delete(model); } } diff --git a/src/main/java/org/pqh/model/AbstractModel.java b/webCrawler-core/src/main/java/org/pqh/core/model/AbstractModel.java similarity index 87% rename from src/main/java/org/pqh/model/AbstractModel.java rename to webCrawler-core/src/main/java/org/pqh/core/model/AbstractModel.java index 18ac1ab..dc6db9d 100644 --- a/src/main/java/org/pqh/model/AbstractModel.java +++ b/webCrawler-core/src/main/java/org/pqh/core/model/AbstractModel.java @@ -1,4 +1,4 @@ -package org.pqh.model; +package org.pqh.core.model; import java.io.Serializable; diff --git a/src/main/java/org/pqh/model/Config.java b/webCrawler-core/src/main/java/org/pqh/core/model/Config.java similarity index 97% rename from src/main/java/org/pqh/model/Config.java rename to webCrawler-core/src/main/java/org/pqh/core/model/Config.java index 54ae9f2..c8e9bc1 100644 --- a/src/main/java/org/pqh/model/Config.java +++ b/webCrawler-core/src/main/java/org/pqh/core/model/Config.java @@ -1,4 +1,4 @@ -package org.pqh.model; +package org.pqh.core.model; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/src/main/java/org/pqh/model/Param.java b/webCrawler-core/src/main/java/org/pqh/core/model/Param.java similarity index 98% rename from src/main/java/org/pqh/model/Param.java rename to webCrawler-core/src/main/java/org/pqh/core/model/Param.java index ade996b..10c3854 100644 --- a/src/main/java/org/pqh/model/Param.java +++ b/webCrawler-core/src/main/java/org/pqh/core/model/Param.java @@ -1,4 +1,4 @@ -package org.pqh.model; +package org.pqh.core.model; import javax.persistence.Basic; import javax.persistence.Column; diff --git a/src/main/java/org/pqh/service/BaseService.java b/webCrawler-core/src/main/java/org/pqh/core/service/BaseService.java similarity index 61% rename from src/main/java/org/pqh/service/BaseService.java rename to webCrawler-core/src/main/java/org/pqh/core/service/BaseService.java index 8379a7b..4fcd70f 100644 --- a/src/main/java/org/pqh/service/BaseService.java +++ b/webCrawler-core/src/main/java/org/pqh/core/service/BaseService.java @@ -1,11 +1,10 @@ -package org.pqh.service; +package org.pqh.core.service; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.pqh.dao.BaseDao; -import org.pqh.model.AbstractModel; -import org.pqh.util.DBAction; -import org.springframework.dao.DataAccessException; +import org.pqh.core.dao.BaseDao; +import org.pqh.core.model.AbstractModel; +import org.pqh.core.util.DBAction; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -16,13 +15,13 @@ import javax.annotation.Resource; @Service public class BaseService { - protected Logger log= LogManager.getLogger(); + protected Logger log = LogManager.getLogger(); @Resource private BaseDao baseDao; - public String curd(DBAction action,T formModel){ - Class tClass= (Class) formModel.getClass(); + public String curd(DBAction action, T formModel) { + Class tClass = (Class) formModel.getClass(); try { switch (action) { case Insert: @@ -36,11 +35,11 @@ public class BaseService { baseDao.delete(tClass, formModel.primaryKey()); break; } - return action+" success"; - }catch (DataAccessException e){ - log.error(formModel.tableNote()+"进行"+action+"操作失败,原因是:"+e.getMessage()); + return action + " success"; + } catch (Exception e) { + log.error(formModel.tableNote() + "进行" + action + "操作失败,原因是:" + e.getMessage()); } - return action+" fail"; + return action + " fail"; } } diff --git a/src/main/java/org/pqh/util/DBAction.java b/webCrawler-core/src/main/java/org/pqh/core/util/DBAction.java similarity index 80% rename from src/main/java/org/pqh/util/DBAction.java rename to webCrawler-core/src/main/java/org/pqh/core/util/DBAction.java index 1fd431c..4ded1ec 100644 --- a/src/main/java/org/pqh/util/DBAction.java +++ b/webCrawler-core/src/main/java/org/pqh/core/util/DBAction.java @@ -1,4 +1,4 @@ -package org.pqh.util; +package org.pqh.core.util; /** * Created by reborn on 2017/8/2. diff --git a/webCrawler-core/src/main/java/org/pqh/core/util/PropertiesUtil.java b/webCrawler-core/src/main/java/org/pqh/core/util/PropertiesUtil.java new file mode 100644 index 0000000..6443724 --- /dev/null +++ b/webCrawler-core/src/main/java/org/pqh/core/util/PropertiesUtil.java @@ -0,0 +1,47 @@ +package org.pqh.core.util; + +import java.io.BufferedInputStream; +import java.util.Properties; + +/** + * Properties工具类 + */ +public final class PropertiesUtil { +// protected static final Logger log = LoggerFactory.getLogger(PropertiesUtil.class); + + private PropertiesUtil() { + + } + + /** + * 根据资源文件名,和name获取对应的value,如果没有对应的值,将返回null + * + * @param resourceFile 资源文件名 + * @param name 对应的value + * @return 对应的值 + */ + public static String getValue(String resourceFile, String name) { + if (resourceFile == null || name == null) { + return null; + } + return loadPropertiesFromResourceFile(resourceFile).getProperty(name); + } + + /** + * 根据资源文件路径,读取资源文件,如果资源文件不存在,将返回默认的[new Properties()] + * + * @param resourceFile 资源文件名 + * @return 资源文件 + */ + public static Properties loadPropertiesFromResourceFile(String resourceFile) { + Properties properties = new Properties(); + try (BufferedInputStream bis = new BufferedInputStream( + PropertiesUtil.class.getClassLoader().getResourceAsStream(resourceFile))) { + properties.load(bis); + return properties; + } catch (Exception e) { +// log.error(e.getMessage(), e); + } + return properties; + } +} \ No newline at end of file