需要有关Quartz调度程序的帮助。这是我到目前为止所做的。
Spring定义
<bean id="firstClass" class="com.my.sample.FirstClass">
// some properties
</bean>
<bean id="secondClass" class="com.my.sample.SecondClass">
// some properties
</bean>
<bean id="myJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.my.sample.quartz.job.MyJob" />
<property name="jobDataAsMap">
<map>
<entry key="firstClass" value-ref="firstClass" />
<entry key="secondClass" value-ref="secondClass" />
</map>
</property>
</bean>
<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="myJob" />
<property name="repeatInterval" value="10000" />
<property name="startDelay" value="1000" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="quartzProperties" ref="quartzProperties" />
<property name="jobDetails">
<list><ref bean="myJob" /></list>
</property>
<property name="triggers">
<list><ref bean="simpleTrigger" /></list>
</property>
</bean>
类实现
public class MyJob extends QuartzJobBean {
private static final Logger LOGGER = LoggerFactory.getLogger(MyJob.class);
private FirstClass firstClass;
private SecondClass secondClass;
@Override
protected void executeInternal(final JobExecutionContext jobExecutionContext) throws JobExecutionException {
LOGGER.info("Executing job...");
final AbcClass abcClass = firstClass.getAbc();
secondClass.testMethod(abcClass);
}
public void setFirstClass(final FirstClass firstClass) {
this.firstClass = firstClass;
}
public void setSecondClass(final SecondClass secondClass) {
this.secondClass = secondClass;
}
}
public interface MyParent {
AbcClass getAbc();
}
public class FirstClass implements MyParent, Serializable {
AbcClass getAbc() {
// generate abcClass from db
return abcClass;
}
}
但是我收到了这样的错误
org.springframework.beans.factory.BeanCreationException:在URL [bundle://343.0:0 / META-INF / spring / osgi]中定义名称为'org.springframework.scheduling.quartz.SchedulerFactoryBean#0'的bean创建错误.xml]:调用init方法失败;嵌套异常是org.quartz.JobPersistenceException:无法为'dataSyncJob'作业存储触发器'simpleTrigger':com.my.sample.MyParent [请参阅嵌套异常:java.lang.ClassNotFoundException:com.my.sample.MyParent] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)[428:org.springframework.beans:3.1.4.RELEASE] ...
项目结构
com.my
|-sample
|-MyParent.java
|-FirstClass.java
|-SecondClass.java
|-quartz.job
|-MyJob.java
|-other
捆绑配置
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Import-Package>
org.quartz.impl.jdbcjobstore.oracle,
org.quartz.simpl,
org.quartz.impl.jdbcjobstore,
*
</Import-Package>
<Export-Package>com.my.*</Export-Package>
<excludeDependencies>*;scope=provided|runtime</excludeDependencies>
<DynamicImport-Package>
org.apache.cxf.*,
org.springframework.beans.*
</DynamicImport-Package>
</instructions>
</configuration>
答案 0 :(得分:0)
看起来你正在做osgi,你需要确保:
如果您使用的是Maven,则可以使用Apache Felix maven-bundle-plugin操作MANIFEST.MF文件。