Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
熊鹏飞
/
xxljob220
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6e86a7e4
authored
Jan 19, 2020
by
xuxueli
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
NPE隐患处理。
parent
039f8d2b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
46 deletions
xxl-job-core/src/main/java/com/xxl/job/core/executor/impl/XxlJobSpringExecutor.java
xxl-job-core/src/main/java/com/xxl/job/core/executor/impl/XxlJobSpringExecutor.java
View file @
6e86a7e4
...
@@ -78,59 +78,62 @@ public class XxlJobSpringExecutor extends XxlJobExecutor implements ApplicationC
...
@@ -78,59 +78,62 @@ public class XxlJobSpringExecutor extends XxlJobExecutor implements ApplicationC
// init job handler from method
// init job handler from method
String
[]
beanDefinitionNames
=
applicationContext
.
getBeanDefinitionNames
();
String
[]
beanDefinitionNames
=
applicationContext
.
getBeanDefinitionNames
();
for
(
String
beanDefinitionName
:
beanDefinitionNames
)
{
if
(
beanDefinitionNames
!=
null
&&
beanDefinitionNames
.
length
>
0
)
{
Object
bean
=
applicationContext
.
getBean
(
beanDefinitionName
);
for
(
String
beanDefinitionName
:
beanDefinitionNames
)
{
Method
[]
methods
=
bean
.
getClass
().
getDeclaredMethods
();
Object
bean
=
applicationContext
.
getBean
(
beanDefinitionName
);
for
(
Method
method:
methods
)
{
Method
[]
methods
=
bean
.
getClass
().
getDeclaredMethods
();
XxlJob
xxlJob
=
AnnotationUtils
.
findAnnotation
(
method
,
XxlJob
.
class
);
for
(
Method
method:
methods
)
{
if
(
xxlJob
!=
null
)
{
XxlJob
xxlJob
=
AnnotationUtils
.
findAnnotation
(
method
,
XxlJob
.
class
);
if
(
xxlJob
!=
null
)
{
// name
String
name
=
xxlJob
.
value
();
// name
if
(
name
.
trim
().
length
()
==
0
)
{
String
name
=
xxlJob
.
value
();
throw
new
RuntimeException
(
"xxl-job method-jobhandler name invalid, for["
+
bean
.
getClass
()
+
"#"
+
method
.
getName
()
+
"] ."
);
if
(
name
.
trim
().
length
()
==
0
)
{
}
throw
new
RuntimeException
(
"xxl-job method-jobhandler name invalid, for["
+
bean
.
getClass
()
+
"#"
+
method
.
getName
()
+
"] ."
);
if
(
loadJobHandler
(
name
)
!=
null
)
{
}
throw
new
RuntimeException
(
"xxl-job jobhandler["
+
name
+
"] naming conflicts."
);
if
(
loadJobHandler
(
name
)
!=
null
)
{
}
throw
new
RuntimeException
(
"xxl-job jobhandler["
+
name
+
"] naming conflicts."
);
}
// execute method
// execute method
if
(!(
method
.
getParameterTypes
()!=
null
&&
method
.
getParameterTypes
().
length
==
1
&&
method
.
getParameterTypes
()[
0
].
isAssignableFrom
(
String
.
class
)))
{
if
(!(
method
.
getParameterTypes
()!=
null
&&
method
.
getParameterTypes
().
length
==
1
&&
method
.
getParameterTypes
()[
0
].
isAssignableFrom
(
String
.
class
)))
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler param-classtype invalid, for["
+
bean
.
getClass
()
+
"#"
+
method
.
getName
()
+
"] , "
+
throw
new
RuntimeException
(
"xxl-job method-jobhandler param-classtype invalid, for["
+
bean
.
getClass
()
+
"#"
+
method
.
getName
()
+
"] , "
+
"The correct method format like \" public ReturnT<String> execute(String param) \" ."
);
"The correct method format like \" public ReturnT<String> execute(String param) \" ."
);
}
if
(!
method
.
getReturnType
().
isAssignableFrom
(
ReturnT
.
class
))
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler return-classtype invalid, for["
+
bean
.
getClass
()
+
"#"
+
method
.
getName
()
+
"] , "
+
"The correct method format like \" public ReturnT<String> execute(String param) \" ."
);
}
method
.
setAccessible
(
true
);
// init and destory
Method
initMethod
=
null
;
Method
destroyMethod
=
null
;
if
(
xxlJob
.
init
().
trim
().
length
()
>
0
)
{
try
{
initMethod
=
bean
.
getClass
().
getDeclaredMethod
(
xxlJob
.
init
());
initMethod
.
setAccessible
(
true
);
}
catch
(
NoSuchMethodException
e
)
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler initMethod invalid, for["
+
bean
.
getClass
()
+
"#"
+
method
.
getName
()
+
"] ."
);
}
}
}
if
(!
method
.
getReturnType
().
isAssignableFrom
(
ReturnT
.
class
))
{
if
(
xxlJob
.
destroy
().
trim
().
length
()
>
0
)
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler return-classtype invalid, for["
+
bean
.
getClass
()
+
"#"
+
method
.
getName
()
+
"] , "
+
try
{
"The correct method format like \" public ReturnT<String> execute(String param) \" ."
);
destroyMethod
=
bean
.
getClass
().
getDeclaredMethod
(
xxlJob
.
destroy
());
}
destroyMethod
.
setAccessible
(
true
);
method
.
setAccessible
(
true
);
}
catch
(
NoSuchMethodException
e
)
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler destroyMethod invalid, for["
+
bean
.
getClass
()
+
"#"
+
method
.
getName
()
+
"] ."
);
// init and destory
Method
initMethod
=
null
;
Method
destroyMethod
=
null
;
if
(
xxlJob
.
init
().
trim
().
length
()
>
0
)
{
try
{
initMethod
=
bean
.
getClass
().
getDeclaredMethod
(
xxlJob
.
init
());
initMethod
.
setAccessible
(
true
);
}
catch
(
NoSuchMethodException
e
)
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler initMethod invalid, for["
+
bean
.
getClass
()
+
"#"
+
method
.
getName
()
+
"] ."
);
}
}
if
(
xxlJob
.
destroy
().
trim
().
length
()
>
0
)
{
try
{
destroyMethod
=
bean
.
getClass
().
getDeclaredMethod
(
xxlJob
.
destroy
());
destroyMethod
.
setAccessible
(
true
);
}
catch
(
NoSuchMethodException
e
)
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler destroyMethod invalid, for["
+
bean
.
getClass
()
+
"#"
+
method
.
getName
()
+
"] ."
);
}
}
}
}
// registry jobhandler
// registry jobhandler
registJobHandler
(
name
,
new
MethodJobHandler
(
bean
,
method
,
initMethod
,
destroyMethod
));
registJobHandler
(
name
,
new
MethodJobHandler
(
bean
,
method
,
initMethod
,
destroyMethod
));
}
}
}
}
}
}
}
}
}
// ---------------------- applicationContext ----------------------
// ---------------------- applicationContext ----------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment