如何使用MongodbJobStore(通过quartz.properties文件)连接到JavaWebApplication项目中的mongodb?
我已发布配置文件quartz.properties连接到mongodb。 这是我的文件quartz.properties如何使用MongodbJobStore(通过quartz.properties文件)连接到JavaWebApplication项目中的mongodb?,java,mongodb,quartz-scheduler,Java,Mongodb,Quartz Scheduler,我已发布配置文件quartz.properties连接到mongodb。 这是我的文件quartz.properties #specify the jobstore used org.quartz.jobStore.class=com.novemberain.quartz.mongodb.MongoDBJobStore org.quartz.jobStore.mongoUri=mongodb://localhost:27017 #The datasource for the jobstore t
#specify the jobstore used
org.quartz.jobStore.class=com.novemberain.quartz.mongodb.MongoDBJobStore
org.quartz.jobStore.mongoUri=mongodb://localhost:27017
#The datasource for the jobstore that is to be used
org.quartz.jobStore.dbName=myds
org.quartz.jobStore.addresses=host1,host2
#quartz table prefixes in the database
org.quartz.jobStore.collectionPrefix=quartz_
org.quartz.threadPool.threadCount = 4
public Scheduler getScheduler(Properties properties) {
SchedulerFactory factory;
if (!properties.isEmpty()) {
// with properties
factory = new StdSchedulerFactory(properties);
} else {
// without properties
factory = new StdSchedulerFactory();
}
return factory.getScheduler();
}
有人能推荐一种支持使用MongoDB的Quartz的方法吗?使用Quartz.properties,还是石英的简单替代品 使用此方法获取具有/不具有属性的计划程序
#specify the jobstore used
org.quartz.jobStore.class=com.novemberain.quartz.mongodb.MongoDBJobStore
org.quartz.jobStore.mongoUri=mongodb://localhost:27017
#The datasource for the jobstore that is to be used
org.quartz.jobStore.dbName=myds
org.quartz.jobStore.addresses=host1,host2
#quartz table prefixes in the database
org.quartz.jobStore.collectionPrefix=quartz_
org.quartz.threadPool.threadCount = 4
public Scheduler getScheduler(Properties properties) {
SchedulerFactory factory;
if (!properties.isEmpty()) {
// with properties
factory = new StdSchedulerFactory(properties);
} else {
// without properties
factory = new StdSchedulerFactory();
}
return factory.getScheduler();
}
此方法用于加载属性文件
public Scheduler load() throws SchedulerException {
Properties prop = new Properties();
try {
// file 'quartz.properties' in the 'src/main/resources/config' (Maven project structure)
properties.load(this.getClass().getResourceAsStream("/config/my-quartz.properties"));
} catch (IOException e) {
// process the exception, maybe load default properties
}
return getScheduler(properties);
}
# Use the MongoDB store
org.quartz.jobStore.class=com.novemberain.quartz.mongodb.MongoDBJobStore
# MongoDB URI (optional if 'org.quartz.jobStore.addresses' is set)
org.quartz.jobStore.mongoUri=mongodb://localhost:27020
# comma separated list of mongodb hosts/replica set seeds (optional if 'org.quartz.jobStore.mongoUri' is set)
org.quartz.jobStore.addresses=host1,host2
# database name
org.quartz.jobStore.dbName=quartz
# Will be used to create collections like mycol_jobs, mycol_triggers, mycol_calendars, mycol_locks
org.quartz.jobStore.collectionPrefix=mycol
# thread count setting is ignored by the MongoDB store but Quartz requries it
org.quartz.threadPool.threadCount=1
您可以将属性文件放入“src/main/resources/config”文件夹
或者设置$JAVA_OPTS=-Dorg.quartz.properties=/config/my-quartz.properties
#specify the jobstore used
org.quartz.jobStore.class=com.novemberain.quartz.mongodb.MongoDBJobStore
org.quartz.jobStore.mongoUri=mongodb://localhost:27017
#The datasource for the jobstore that is to be used
org.quartz.jobStore.dbName=myds
org.quartz.jobStore.addresses=host1,host2
#quartz table prefixes in the database
org.quartz.jobStore.collectionPrefix=quartz_
org.quartz.threadPool.threadCount = 4
public Scheduler getScheduler(Properties properties) {
SchedulerFactory factory;
if (!properties.isEmpty()) {
// with properties
factory = new StdSchedulerFactory(properties);
} else {
// without properties
factory = new StdSchedulerFactory();
}
return factory.getScheduler();
}
还可以使用Spring加载属性
@Component
public class SchedulerLoader {
@Value("${org.quartz.jobStore.class}")
private String quartzJobStoreClass;
@Value("${org.quartz.jobStore.mongoUri}")
private String quartzJobStoreMongoUri;
@Value("${org.quartz.jobStore.dbName}")
private String quartzJobStoreDbName;
@Value("${org.quartz.jobStore.collectionPrefix}")
private String quartzJobStoreCollectionPrefix;
@Value("${org.quartz.threadPool.threadCount}")
private String quartzThreadPoolThreadCount;
@Value("${org.quartz.jobStore.addresses}")
private String quartzJobStoreAddresses;
public Scheduler load() throws SchedulerException {
Properties properties = new Properties();
try {
properties.setProperty("org.quartz.jobStore.class", quartzJobStoreClass);
properties.setProperty("org.quartz.jobStore.mongoUri", quartzJobStoreMongoUri);
properties.setProperty("org.quartz.jobStore.dbName", quartzJobStoreDbName);
properties.setProperty("org.quartz.jobStore.collectionPrefix", quartzJobStoreCollectionPrefix);
properties.setProperty("org.quartz.threadPool.threadCount", quartzThreadPoolThreadCount);
properties.setProperty("org.quartz.jobStore.addresses", quartzJobStoreAddresses);
} catch (IOException e) {
// process the exception, maybe load default properties
}
return getScheduler(properties);
}
...
使用Spring配置
<beans ...>
...
<context:annotation-config/>
<context:property-placeholder location="classpath:config/*.properties"/>
...
您还应该添加Maven依赖项(查看详细信息)
com.novenbeain
石英蒙哥达
2.0.0-rc1
您遇到了什么问题?什么不起作用?您是否看到任何错误?我正在尝试使用quartz.properties连接到db(mongodb),但我不知道如何才能做到这一点:(…我一直跟着。