本篇内容主要讲解“Quartz注解方式怎么配置”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Quartz注解方式怎么配置”吧!
@Configuration
@PropertySource("classpath:context-datasource.properties")
public class DataSourceElConfig {
private static Logger logger = Logger.getLogger(DataSourceElConfig.class);
@Value("${workDesk.jdbc.driverclass}")
private String driverClass;
@Value("${workDesk.jdbc.url}")
private String jdbcUrl;
@Value("${workDesk.jdbc.username}")
private String user;
@Value("${workDesk.jdbc.password}")
private String password;
@Value("${workDesk.jdbc.poolsize.max}")
private int maxPoolSize;
@Value("${workDesk.jdbc.poolsize.min}")
private int minPoolSize;
@Value("${workDesk.jdbc.poolsize.initial}")
private int initialPoolSize;
@Value("${workDesk.jdbc.idletime.max}")
private int maxIdleTime;
@Value("${workDesk.jdbc.idleConnectionTestPeriod}")
private int idleConnectionTestPeriod;
@Value("${workDesk.read.jdbc.driverclass}")
private String readDriverClass;
@Value("${workDesk.read.jdbc.url}")
private String readJdbcUrl;
@Value("${workDesk.read.jdbc.username}")
private String readUser;
@Value("${workDesk.read.jdbc.password}")
private String readPassword;
@Value("${workDesk.read.jdbc.poolsize.max}")
private int readMaxPoolSize;
@Value("${workDesk.read.jdbc.poolsize.min}")
private int readMinPoolSize;
@Value("${workDesk.read.jdbc.poolsize.initial}")
private int readInitialPoolSize;
@Value("${workDesk.read.jdbc.idletime.max}")
private int readMaxIdleTime;
@Value("${workDesk.read.jdbc.idleConnectionTestPeriod}")
private int readIdleConnectionTestPeriod;
@Value("${redis.pool.maxActive}")
private int maxTotal;
@Value("${redis.pool.maxIdle}")
private int maxIdle;
@Value("${redis.pool.maxWait}")
private long maxWaitMillis;
@Value("${redis.ip}")
private String redisIp;
@Value("${redis.port}")
private int redisPort;
@Value("${redis.password}")
private String redisPassword;
@Value("${redis.timeout}")
private int redisTimeout;
@Value("${redis.default.db}")
private int redisDb;
@Value("${mongodb.host}")
private String mongoHost;
@Value("${mongodb.port}")
private int mongoPort;
@Value("${mongodb.database}")
private String mongoUserName;
@Value("${mongodb.username}")
private String mongoDB;
@Value("${mongodb.password}")
private String mongoPassword;
@Value("${activeMq}")
private String activeMq;
@Autowired
private Environment environment;
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigure() {
return new PropertySourcesPlaceholderConfigurer();
}
/**
* MySql Master 写库数据源
*
* @return
*/
@Bean(name = "platformTomcat", destroyMethod = "close")
public ComboPooledDataSource platformTomcat() {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
try {
dataSource.setDriverClass(driverClass);
}
catch (PropertyVetoException e) {
logger.error("数据源配置,无法找到配置类", e);
}
dataSource.setJdbcUrl(jdbcUrl);
dataSource.setUser(user);
dataSource.setPassword(password);
dataSource.setMaxPoolSize(maxPoolSize);
dataSource.setMinPoolSize(minPoolSize);
dataSource.setInitialPoolSize(initialPoolSize);
dataSource.setMaxIdleTime(maxIdleTime);
dataSource.setTestConnectionOnCheckin(true);
dataSource.setPreferredTestQuery("SELECT 1");
dataSource.setIdleConnectionTestPeriod(idleConnectionTestPeriod);
return dataSource;
}
/**
* MySql Slave 读库数据源
*
* @return
*/
@Bean(name = "platformReadTomcat", destroyMethod = "close")
public ComboPooledDataSource platformReadTomcat() {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
try {
dataSource.setDriverClass(readDriverClass);
}
catch (PropertyVetoException e) {
logger.error("数据源配置,无法找到配置类", e);
}
dataSource.setJdbcUrl(readJdbcUrl);
dataSource.setUser(readUser);
dataSource.setPassword(readPassword);
dataSource.setMaxPoolSize(readMaxPoolSize);
dataSource.setMinPoolSize(readMinPoolSize);
dataSource.setInitialPoolSize(readInitialPoolSize);
dataSource.setMaxIdleTime(readMaxIdleTime);
dataSource.setTestConnectionOnCheckin(true);
dataSource.setPreferredTestQuery("SELECT 1");
dataSource.setIdleConnectionTestPeriod(readIdleConnectionTestPeriod);
return dataSource;
}
/**
* Redis 连接池配置信息
*
* @return
*/
@Bean(name = "jedisPoolConfig")
public JedisPoolConfig jedisPoolConfig() {
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxTotal(maxTotal);
jedisPoolConfig.setMaxIdle(maxIdle);
jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
jedisPoolConfig.setTestOnBorrow(true);
return jedisPoolConfig;
}
@Bean(name = "jedisConnectionFactory")
public JedisConnectionFactory jedisConnectionFactory(JedisPoolConfig jedisPoolConfig) {
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(jedisPoolConfig);
jedisConnectionFactory.setUsePool(true);
jedisConnectionFactory.setHostName(redisIp);
jedisConnectionFactory.setPort(redisPort);
jedisConnectionFactory.setPassword(redisPassword);
jedisConnectionFactory.setTimeout(redisTimeout);
jedisConnectionFactory.setDatabase(redisDb);
jedisConnectionFactory.afterPropertiesSet();
return jedisConnectionFactory;
}
@Bean(name = "keySerializer")
public StringRedisSerializer keySerializer() {
return new StringRedisSerializer();
}
@Bean(name = "valueSerializer")
public JdkSerializationRedisSerializer valueSerializer() {
return new JdkSerializationRedisSerializer();
}
/**
* MongoDB 配置
*
* @return
*/
@Bean(name = "mongoDbFactory")
public MongoDbFactory mongoDbFactory() throws Exception {
MongoCredential credential = MongoCredential.createCredential(mongoUserName, mongoDB,
mongoPassword.toCharArray());
ServerAddress serverAddress = new ServerAddress(mongoHost, mongoPort);
MongoClient mongoClient = new MongoClient(serverAddress, Arrays.asList(credential));
SimpleMongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(mongoClient, mongoDB);
return mongoDbFactory;
}
@Bean(name="mongoConverter")
public MongoConverter mongoConverter(MongoDbFactory mongoDbFactory) {
MappingMongoConverter mongoConverter = new MappingMongoConverter(new DefaultDbRefResolver(mongoDbFactory),
new MongoMappingContext());
// 不插入_class
mongoConverter.setTypeMapper(new DefaultMongoTypeMapper(null));
return mongoConverter;
}
/**
* Jms 配置
* @return
*/
@Bean(name="activeMQConnectionFactory")
public ActiveMQConnectionFactory activeMQConnectionFactory()
{
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
activeMQConnectionFactory.setUseAsyncSend(false);
activeMQConnectionFactory.setBrokerURL(activeMq);
return activeMQConnectionFactory;
}
@Bean(name="cachingConnectionFactory")
public CachingConnectionFactory cachingConnectionFactory(ActiveMQConnectionFactory targetConnectionFactory)
{
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(targetConnectionFactory);
cachingConnectionFactory.setSessionCacheSize(10);
return cachingConnectionFactory;
}
}
@Configuration
@PropertySource("classpath:context-datasource.properties")
public class DataSourceElConfig {
private static Logger logger = Logger.getLogger(DataSourceElConfig.class);
@Value("${workDesk.jdbc.driverclass}")
private String driverClass;
@Value("${workDesk.jdbc.url}")
private String jdbcUrl;
@Value("${workDesk.jdbc.username}")
private String user;
@Value("${workDesk.jdbc.password}")
private String password;
@Value("${workDesk.jdbc.poolsize.max}")
private int maxPoolSize;
@Value("${workDesk.jdbc.poolsize.min}")
private int minPoolSize;
@Value("${workDesk.jdbc.poolsize.initial}")
private int initialPoolSize;
@Value("${workDesk.jdbc.idletime.max}")
private int maxIdleTime;
@Value("${workDesk.jdbc.idleConnectionTestPeriod}")
private int idleConnectionTestPeriod;
@Value("${workDesk.read.jdbc.driverclass}")
private String readDriverClass;
@Value("${workDesk.read.jdbc.url}")
private String readJdbcUrl;
@Value("${workDesk.read.jdbc.username}")
private String readUser;
@Value("${workDesk.read.jdbc.password}")
private String readPassword;
@Value("${workDesk.read.jdbc.poolsize.max}")
private int readMaxPoolSize;
@Value("${workDesk.read.jdbc.poolsize.min}")
private int readMinPoolSize;
@Value("${workDesk.read.jdbc.poolsize.initial}")
private int readInitialPoolSize;
@Value("${workDesk.read.jdbc.idletime.max}")
private int readMaxIdleTime;
@Value("${workDesk.read.jdbc.idleConnectionTestPeriod}")
private int readIdleConnectionTestPeriod;
@Value("${redis.pool.maxActive}")
private int maxTotal;
@Value("${redis.pool.maxIdle}")
private int maxIdle;
@Value("${redis.pool.maxWait}")
private long maxWaitMillis;
@Value("${redis.ip}")
private String redisIp;
@Value("${redis.port}")
private int redisPort;
@Value("${redis.password}")
private String redisPassword;
@Value("${redis.timeout}")
private int redisTimeout;
@Value("${redis.default.db}")
private int redisDb;
@Value("${mongodb.host}")
private String mongoHost;
@Value("${mongodb.port}")
private int mongoPort;
@Value("${mongodb.database}")
private String mongoUserName;
@Value("${mongodb.username}")
private String mongoDB;
@Value("${mongodb.password}")
private String mongoPassword;
@Value("${activeMq}")
private String activeMq;
@Autowired
private Environment environment;
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigure() {
return new PropertySourcesPlaceholderConfigurer();
}
/**
* MySql Master 写库数据源
*
* @return
*/
@Bean(name = "platformTomcat", destroyMethod = "close")
public ComboPooledDataSource platformTomcat() {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
try {
dataSource.setDriverClass(driverClass);
}
catch (PropertyVetoException e) {
logger.error("数据源配置,无法找到配置类", e);
}
dataSource.setJdbcUrl(jdbcUrl);
dataSource.setUser(user);
dataSource.setPassword(password);
dataSource.setMaxPoolSize(maxPoolSize);
dataSource.setMinPoolSize(minPoolSize);
dataSource.setInitialPoolSize(initialPoolSize);
dataSource.setMaxIdleTime(maxIdleTime);
dataSource.setTestConnectionOnCheckin(true);
dataSource.setPreferredTestQuery("SELECT 1");
dataSource.setIdleConnectionTestPeriod(idleConnectionTestPeriod);
return dataSource;
}
/**
* MySql Slave 读库数据源
*
* @return
*/
@Bean(name = "platformReadTomcat", destroyMethod = "close")
public ComboPooledDataSource platformReadTomcat() {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
try {
dataSource.setDriverClass(readDriverClass);
}
catch (PropertyVetoException e) {
logger.error("数据源配置,无法找到配置类", e);
}
dataSource.setJdbcUrl(readJdbcUrl);
dataSource.setUser(readUser);
dataSource.setPassword(readPassword);
dataSource.setMaxPoolSize(readMaxPoolSize);
dataSource.setMinPoolSize(readMinPoolSize);
dataSource.setInitialPoolSize(readInitialPoolSize);
dataSource.setMaxIdleTime(readMaxIdleTime);
dataSource.setTestConnectionOnCheckin(true);
dataSource.setPreferredTestQuery("SELECT 1");
dataSource.setIdleConnectionTestPeriod(readIdleConnectionTestPeriod);
return dataSource;
}
/**
* Redis 连接池配置信息
*
* @return
*/
@Bean(name = "jedisPoolConfig")
public JedisPoolConfig jedisPoolConfig() {
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxTotal(maxTotal);
jedisPoolConfig.setMaxIdle(maxIdle);
jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
jedisPoolConfig.setTestOnBorrow(true);
return jedisPoolConfig;
}
@Bean(name = "jedisConnectionFactory")
public JedisConnectionFactory jedisConnectionFactory(JedisPoolConfig jedisPoolConfig) {
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(jedisPoolConfig);
jedisConnectionFactory.setUsePool(true);
jedisConnectionFactory.setHostName(redisIp);
jedisConnectionFactory.setPort(redisPort);
jedisConnectionFactory.setPassword(redisPassword);
jedisConnectionFactory.setTimeout(redisTimeout);
jedisConnectionFactory.setDatabase(redisDb);
jedisConnectionFactory.afterPropertiesSet();
return jedisConnectionFactory;
}
@Bean(name = "keySerializer")
public StringRedisSerializer keySerializer() {
return new StringRedisSerializer();
}
@Bean(name = "valueSerializer")
public JdkSerializationRedisSerializer valueSerializer() {
return new JdkSerializationRedisSerializer();
}
/**
* MongoDB 配置
*
* @return
*/
@Bean(name = "mongoDbFactory")
public MongoDbFactory mongoDbFactory() throws Exception {
MongoCredential credential = MongoCredential.createCredential(mongoUserName, mongoDB,
mongoPassword.toCharArray());
ServerAddress serverAddress = new ServerAddress(mongoHost, mongoPort);
MongoClient mongoClient = new MongoClient(serverAddress, Arrays.asList(credential));
SimpleMongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(mongoClient, mongoDB);
return mongoDbFactory;
}
@Bean(name="mongoConverter")
public MongoConverter mongoConverter(MongoDbFactory mongoDbFactory) {
MappingMongoConverter mongoConverter = new MappingMongoConverter(new DefaultDbRefResolver(mongoDbFactory),
new MongoMappingContext());
// 不插入_class
mongoConverter.setTypeMapper(new DefaultMongoTypeMapper(null));
return mongoConverter;
}
/**
* Jms 配置
* @return
*/
@Bean(name="activeMQConnectionFactory")
public ActiveMQConnectionFactory activeMQConnectionFactory()
{
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
activeMQConnectionFactory.setUseAsyncSend(false);
activeMQConnectionFactory.setBrokerURL(activeMq);
return activeMQConnectionFactory;
}
@Bean(name="cachingConnectionFactory")
public CachingConnectionFactory cachingConnectionFactory(ActiveMQConnectionFactory targetConnectionFactory)
{
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(targetConnectionFactory);
cachingConnectionFactory.setSessionCacheSize(10);
return cachingConnectionFactory;
}
}
到此,相信大家对“Quartz注解方式怎么配置”有了更深的了解,不妨来实际操作一番吧!这里是天达云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!