Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
智布道
OneBlog
提交
dfdf1001
O
OneBlog
项目概览
智布道
/
OneBlog
9 个月 前同步成功
通知
11
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
OneBlog
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
dfdf1001
编写于
10月 28, 2021
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
🐛
修复【文章搬运工】抓取文章失败的问题
上级
922f81ec
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
6 addition
and
99 deletion
+6
-99
blog-core/pom.xml
blog-core/pom.xml
+0
-30
blog-core/src/main/java/com/zyd/blog/business/service/impl/RemoverServiceImpl.java
...om/zyd/blog/business/service/impl/RemoverServiceImpl.java
+3
-1
blog-core/src/main/java/com/zyd/blog/framework/config/AsyncConfig.java
.../main/java/com/zyd/blog/framework/config/AsyncConfig.java
+1
-66
pom.xml
pom.xml
+2
-2
未找到文件。
blog-core/pom.xml
浏览文件 @
dfdf1001
...
...
@@ -199,36 +199,6 @@
<groupId>
me.zhyd.hunter
</groupId>
<artifactId>
blog-hunter
</artifactId>
<version>
${blog-hunter.version}
</version>
<exclusions>
<exclusion>
<groupId>
org.hibernate.validator
</groupId>
<artifactId>
hibernate-validator
</artifactId>
</exclusion>
<exclusion>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
</exclusion>
<exclusion>
<groupId>
org.jsoup
</groupId>
<artifactId>
jsoup
</artifactId>
</exclusion>
<exclusion>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
</exclusion>
<exclusion>
<artifactId>
lombok
</artifactId>
<groupId>
org.projectlombok
</groupId>
</exclusion>
<exclusion>
<artifactId>
commons-collections
</artifactId>
<groupId>
commons-collections
</groupId>
</exclusion>
<exclusion>
<artifactId>
commons-io
</artifactId>
<groupId>
commons-io
</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
com.zyd
</groupId>
...
...
blog-core/src/main/java/com/zyd/blog/business/service/impl/RemoverServiceImpl.java
浏览文件 @
dfdf1001
...
...
@@ -89,7 +89,8 @@ public class RemoverServiceImpl implements RemoverService {
private
void
saveArticles
(
Long
typeId
,
HunterConfig
config
,
HunterPrintWriter
writerUtil
,
CopyOnWriteArrayList
<
VirtualArticle
>
list
)
{
// 获取数据库中的标签列表
Map
<
String
,
Long
>
originalTags
=
tagsService
.
listAll
().
stream
().
collect
(
Collectors
.
toMap
(
tag
->
tag
.
getName
().
toUpperCase
(),
Tags:
:
getId
));
List
<
Tags
>
tags
=
tagsService
.
listAll
();
Map
<
String
,
Long
>
originalTags
=
tags
.
stream
().
collect
(
Collectors
.
toMap
(
tag
->
tag
.
getName
().
toUpperCase
(),
Tags:
:
getId
));
User
user
=
SessionUtil
.
getUser
();
// 添加文章到数据库
...
...
@@ -115,6 +116,7 @@ public class RemoverServiceImpl implements RemoverService {
article
.
setIsMarkdown
(
false
);
article
.
setDescription
(
virtualArticle
.
getDescription
());
article
.
setKeywords
(
virtualArticle
.
getKeywords
());
article
.
setEditorType
(
"we"
);
article
=
articleService
.
insert
(
article
);
writerUtil
.
print
(
String
.
format
(
"[ save ] Succeed! <a href=\"%s\" target=\"_blank\">%s</a>"
,
virtualArticle
.
getSource
(),
article
.
getTitle
()));
return
article
;
...
...
blog-core/src/main/java/com/zyd/blog/framework/config/AsyncConfig.java
浏览文件 @
dfdf1001
package
com.zyd.blog.framework.config
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.AsyncConfigurer
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.util.concurrent.ListenableFuture
;
import
org.springframework.web.context.request.RequestAttributes
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
java.lang.reflect.Method
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.Future
;
/**
* 异步线程配置
...
...
@@ -28,58 +16,5 @@ import java.util.concurrent.Future;
@Slf4j
@Configuration
@EnableAsync
public
class
AsyncConfig
implements
AsyncConfigurer
{
@Override
@Bean
public
Executor
getAsyncExecutor
()
{
return
new
ContextAwarePoolExecutor
();
}
@Override
public
AsyncUncaughtExceptionHandler
getAsyncUncaughtExceptionHandler
()
{
return
new
SpringAsyncExceptionHandler
();
}
class
SpringAsyncExceptionHandler
implements
AsyncUncaughtExceptionHandler
{
@Override
public
void
handleUncaughtException
(
Throwable
throwable
,
Method
method
,
Object
...
objects
)
{
log
.
error
(
"异步线程发生异常!Method [{}],Error Message [{}]"
,
method
.
getName
(),
throwable
.
getMessage
());
}
}
public
class
ContextAwarePoolExecutor
extends
ThreadPoolTaskExecutor
{
@Override
public
<
T
>
Future
<
T
>
submit
(
Callable
<
T
>
task
)
{
return
super
.
submit
(
new
ContextAwareCallable
(
task
,
RequestContextHolder
.
currentRequestAttributes
()));
}
@Override
public
<
T
>
ListenableFuture
<
T
>
submitListenable
(
Callable
<
T
>
task
)
{
return
super
.
submitListenable
(
new
ContextAwareCallable
(
task
,
RequestContextHolder
.
currentRequestAttributes
()));
}
}
public
class
ContextAwareCallable
<
T
>
implements
Callable
<
T
>
{
private
Callable
<
T
>
task
;
private
RequestAttributes
context
;
public
ContextAwareCallable
(
Callable
<
T
>
task
,
RequestAttributes
context
)
{
this
.
task
=
task
;
this
.
context
=
context
;
}
@Override
public
T
call
()
throws
Exception
{
if
(
context
!=
null
)
{
RequestContextHolder
.
setRequestAttributes
(
context
);
}
try
{
return
task
.
call
();
}
finally
{
RequestContextHolder
.
resetRequestAttributes
();
}
}
}
public
class
AsyncConfig
{
}
pom.xml
浏览文件 @
dfdf1001
...
...
@@ -31,7 +31,7 @@
<java.version>
1.8
</java.version>
<maven.test.skip>
true
</maven.test.skip>
<webmagic.version>
0.7.3
</webmagic.version>
<jsoup.version>
1.1
4
.2
</jsoup.version>
<jsoup.version>
1.1
0
.2
</jsoup.version>
<javax.validation.version>
2.0.1.Final
</javax.validation.version>
<hibernate.validator.version>
7.0.1.Final
</hibernate.validator.version>
<excel4j.version>
2.1.4-Final
</excel4j.version>
...
...
@@ -48,7 +48,7 @@
<useragentutils.version>
1.21
</useragentutils.version>
<braum.version>
1.0.0-alpha
</braum.version>
<hutool.version>
5.5.7
</hutool.version>
<spring.web.version>
5.1.
4
.RELEASE
</spring.web.version>
<spring.web.version>
5.1.
17
.RELEASE
</spring.web.version>
<aliyun.oss.version>
2.8.3
</aliyun.oss.version>
<blog-hunter.version>
1.0.4
</blog-hunter.version>
<jap.version>
1.0.4
</jap.version>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录