程序运行报错
2013-9-29 16:00:07 org.apache.catalina.core.ApplicationContext log
严重: StandardWrapper.Throwable
java.lang.InstantiationError: org.quartz.JobDetail
at servlet.UniversalQuartzManager.start(UniversalQuartzManager.java:43)
......
请各位帮我解决一下,本人新手,越详细越好,谢谢!!!!
程序如下:
package servlet;
import java.text.ParseException;
import java.util.Date;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
public class UniversalQuartzManager {
private static UniversalQuartzManager instance = null;
private Scheduler sched = null;
private SchedulerFactory factory = null;
private UniversalQuartzManager() {
_init();
}
private void _init() {
factory = new StdSchedulerFactory();
try {
sched = factory.getScheduler();
} catch (SchedulerException e) {
e.printStackTrace();
}
}
public synchronized static UniversalQuartzManager getInstance() {
if (instance == null) {
instance = new UniversalQuartzManager();
}
return instance;
}
public void start() {
try {
sched.start();
// 在这里加载需要执行的业务逻辑类UniversalQuartz.class
JobDetail detail = new JobDetail("cmhksynchron", "cmhkSynch",UniversalQuartz.class);
CronTrigger trigger = new CronTrigger();
// 手动添加了时间
System.out.println("UniversalQuartzManager");
trigger.setCronExpression("2 * * * * ?");
// trigger.setCronExpression("0 0-59 16 * * ?");
trigger.setName("abintrigger");
trigger.setStartTime(new Date());
sched.scheduleJob(detail, trigger);
} catch (SchedulerException e) {
e.printStackTrace();
} catch (ParseException e2) {
e2.printStackTrace();
}
}
public void stop() {
try {
sched.shutdown();
sched = factory.getScheduler();
} catch (SchedulerException e) {
e.printStackTrace();
}
}
public void refresh() {
// 未知的原因,程序执行这段判断进入stop(),在sched.shutdown();这一句报错,//所以暂时将其屏蔽,以待后来解决
// try {
// if(sched != null && sched.isStarted()) {
// this.stop();
// }
this.start();
// } catch (SchedulerException e) {
// e.printStackTrace();
// }
}
}
14 个解决方案
#1
自己顶一个!!!
#2
自己顶一个!!!
#3
jar包是否引用全了?
#4
检查一下你的配置文件是否正确了,web.xml中是否引用正确了你的定时配置文件。
#5
这个是什么意思 能说的详细一点吗?
#6
我用main()函数测试的时候 程序又能正确执行。让tomcat一运行就执行,就报上面的错误!!
#7
有点乱,你可以写Listener, 实现ServletContextListener,然后在contextInitialized里面调用你的任务,看看这个
public class TaskListener implements ServletContextListener {
public void contextDestroyed(ServletContextEvent arg0) {
}
public void contextInitialized(ServletContextEvent sce) {
System.out.println("服务器启动时执行");
JobDetail jobDetail = new JobDetail("job1_2", "jGroup1",
TaskWorkJob.class);
CronTrigger cronTrigger = new CronTrigger("trigger1_2", "tgroup1");
try {
cronTrigger.setCronExpression("0/5 * * * * ?");
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
Scheduler scheduler;
try {
scheduler = schedulerFactory.getScheduler();
scheduler.scheduleJob(jobDetail, cronTrigger);
scheduler.start();
} catch (SchedulerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
web.xml里面配置
<listener>
<listener-class>listener.TaskListener</listener-class>
</listener>
public class TaskListener implements ServletContextListener {
public void contextDestroyed(ServletContextEvent arg0) {
}
public void contextInitialized(ServletContextEvent sce) {
System.out.println("服务器启动时执行");
JobDetail jobDetail = new JobDetail("job1_2", "jGroup1",
TaskWorkJob.class);
CronTrigger cronTrigger = new CronTrigger("trigger1_2", "tgroup1");
try {
cronTrigger.setCronExpression("0/5 * * * * ?");
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
Scheduler scheduler;
try {
scheduler = schedulerFactory.getScheduler();
scheduler.scheduleJob(jobDetail, cronTrigger);
scheduler.start();
} catch (SchedulerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
web.xml里面配置
<listener>
<listener-class>listener.TaskListener</listener-class>
</listener>
#8
改完了以后出现这样的问题:
信息: Deploying web application directory rpts
服务器启动时执行
2013-9-30 9:53:15 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class servlet.UniversalQuartzManager
java.lang.InstantiationError: org.quartz.JobDetail
好像还是说 JobDetail 不能初始化。
信息: Deploying web application directory rpts
服务器启动时执行
2013-9-30 9:53:15 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class servlet.UniversalQuartzManager
java.lang.InstantiationError: org.quartz.JobDetail
好像还是说 JobDetail 不能初始化。
#9
检查下你的web.xml 有没有加入quartz配置,如下:
<!-- Quartz-->
<servlet>
<servlet-name>QuartzInitializer</servlet-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>config-file</param-name>
<param-value>quartz.properties</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Quartz-->
<servlet>
<servlet-name>QuartzInitializer</servlet-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>config-file</param-name>
<param-value>quartz.properties</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
#10
缺少默认构造函数, spring无法初始化
#11
我没有用到到spring的。
用main()函数测试运行,可以运行。
用main()函数测试运行,可以运行。
#12
<param-name>config-file</param-name>
<param-value>quartz.properties</param-value>
文件里面配置什么的,我是要tomcat运行就能执行UniversalQuartzManager里面的方法
#13
这个配置无关spring呀,你是web项目需要初始化quartz,必须在web.xml中配置进去了,要不然你不能够启动定时调度的了,你看你的出错提示也是这么提示的了
#14
<servlet>
<servlet-name>
QuartzInitializer
</servlet-name>
<servlet-class>
org.quartz.ee.servlet.QuartzInitializerServlet
</servlet-class>
<load-on-startup>
1
</load-on-startup>
</servlet>
<servlet>
<servlet-name>InitBuild</servlet-name>
<servlet-class>servlet.InitBuild</servlet-class>
<load-on-startup>4</load-on-startup>
</servlet>
麻烦再帮我看一下 这样配置是不是 先加载QuartzInitializerServlet 在运行InitBuild。但还是 java.lang.InstantiationError: org.quartz.JobDetail
#1
自己顶一个!!!
#2
自己顶一个!!!
#3
jar包是否引用全了?
#4
检查一下你的配置文件是否正确了,web.xml中是否引用正确了你的定时配置文件。
#5
这个是什么意思 能说的详细一点吗?
#6
我用main()函数测试的时候 程序又能正确执行。让tomcat一运行就执行,就报上面的错误!!
#7
有点乱,你可以写Listener, 实现ServletContextListener,然后在contextInitialized里面调用你的任务,看看这个
public class TaskListener implements ServletContextListener {
public void contextDestroyed(ServletContextEvent arg0) {
}
public void contextInitialized(ServletContextEvent sce) {
System.out.println("服务器启动时执行");
JobDetail jobDetail = new JobDetail("job1_2", "jGroup1",
TaskWorkJob.class);
CronTrigger cronTrigger = new CronTrigger("trigger1_2", "tgroup1");
try {
cronTrigger.setCronExpression("0/5 * * * * ?");
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
Scheduler scheduler;
try {
scheduler = schedulerFactory.getScheduler();
scheduler.scheduleJob(jobDetail, cronTrigger);
scheduler.start();
} catch (SchedulerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
web.xml里面配置
<listener>
<listener-class>listener.TaskListener</listener-class>
</listener>
public class TaskListener implements ServletContextListener {
public void contextDestroyed(ServletContextEvent arg0) {
}
public void contextInitialized(ServletContextEvent sce) {
System.out.println("服务器启动时执行");
JobDetail jobDetail = new JobDetail("job1_2", "jGroup1",
TaskWorkJob.class);
CronTrigger cronTrigger = new CronTrigger("trigger1_2", "tgroup1");
try {
cronTrigger.setCronExpression("0/5 * * * * ?");
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
Scheduler scheduler;
try {
scheduler = schedulerFactory.getScheduler();
scheduler.scheduleJob(jobDetail, cronTrigger);
scheduler.start();
} catch (SchedulerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
web.xml里面配置
<listener>
<listener-class>listener.TaskListener</listener-class>
</listener>
#8
改完了以后出现这样的问题:
信息: Deploying web application directory rpts
服务器启动时执行
2013-9-30 9:53:15 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class servlet.UniversalQuartzManager
java.lang.InstantiationError: org.quartz.JobDetail
好像还是说 JobDetail 不能初始化。
信息: Deploying web application directory rpts
服务器启动时执行
2013-9-30 9:53:15 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class servlet.UniversalQuartzManager
java.lang.InstantiationError: org.quartz.JobDetail
好像还是说 JobDetail 不能初始化。
#9
检查下你的web.xml 有没有加入quartz配置,如下:
<!-- Quartz-->
<servlet>
<servlet-name>QuartzInitializer</servlet-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>config-file</param-name>
<param-value>quartz.properties</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Quartz-->
<servlet>
<servlet-name>QuartzInitializer</servlet-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>config-file</param-name>
<param-value>quartz.properties</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
#10
缺少默认构造函数, spring无法初始化
#11
我没有用到到spring的。
用main()函数测试运行,可以运行。
用main()函数测试运行,可以运行。
#12
<param-name>config-file</param-name>
<param-value>quartz.properties</param-value>
文件里面配置什么的,我是要tomcat运行就能执行UniversalQuartzManager里面的方法
#13
这个配置无关spring呀,你是web项目需要初始化quartz,必须在web.xml中配置进去了,要不然你不能够启动定时调度的了,你看你的出错提示也是这么提示的了
#14
<servlet>
<servlet-name>
QuartzInitializer
</servlet-name>
<servlet-class>
org.quartz.ee.servlet.QuartzInitializerServlet
</servlet-class>
<load-on-startup>
1
</load-on-startup>
</servlet>
<servlet>
<servlet-name>InitBuild</servlet-name>
<servlet-class>servlet.InitBuild</servlet-class>
<load-on-startup>4</load-on-startup>
</servlet>
麻烦再帮我看一下 这样配置是不是 先加载QuartzInitializerServlet 在运行InitBuild。但还是 java.lang.InstantiationError: org.quartz.JobDetail