您好,登錄后才能下訂單哦!
本篇內容主要講解“Quartz注解方式怎么配置”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Quartz注解方式怎么配置”吧!
一:目錄結構
二:統一配置文件
context-datasource.properties
workDesk.jdbc.driverclass=com.mysql.jdbc.Driver
workDesk.jdbc.url=jdbc:mysql://10.243.3.18:3306/system?userUnicode=true&characterEncoding=UTF-8
workDesk.jdbc.username=root
workDesk.jdbc.password=$Fortune2015
workDesk.jdbc.poolsize.max=3
workDesk.jdbc.poolsize.min=3
workDesk.jdbc.poolsize.initial=2
workDesk.jdbc.idletime.max=25000
workDesk.jdbc.idleConnectionTestPeriod=18000
#-------workDesk jdbc--------
workDesk.read.jdbc.driverclass=com.mysql.jdbc.Driver
workDesk.read.jdbc.url=jdbc:mysql://10.243.3.18:3306/system?userUnicode=true&characterEncoding=UTF-8
workDesk.read.jdbc.username=root
workDesk.read.jdbc.password=$Fortune2015
workDesk.read.jdbc.poolsize.max=3
workDesk.read.jdbc.poolsize.min=3
workDesk.read.jdbc.poolsize.initial=2
workDesk.read.jdbc.idletime.max=25000
workDesk.read.jdbc.idleConnectionTestPeriod=18000
#--------------redis conf------------
redis.ip=10.243.3.18
redis.port=6379
redis.password=$Fortune2015
redis.default.db=0
redis.timeout=30000
redis.pool.maxActive=1024
redis.pool.maxIdle=200
redis.pool.maxWait=1000
redis.pool.testOnBorrow=true
#------------------jms server-------------
activeMq=failover:(tcp://10.243.3.18:61616,tcp://10.243.3.18:61616)?randomize=false
#--------------mongodb conf------------
mongodb.host=10.243.3.27
mongodb.port=27017
mongodb.database=gmap
mongodb.username=mongodb
mongodb.password=$Fortune2016
systemConfig.properties
點擊(此處)折疊或打開
#=======================================================================================
#MailSender Config
#=======================================================================================
mail.host=smtp.mxhichina.com
三:配置文件
@Configuration
@EnableScheduling
@EnableCaching
@EnableTransactionManagement(proxyTargetClass = true)
@ComponentScan("com.gemdale,com.enjoylink")
@Import({DataSourceElConfig.class,TransactionManagerElConfig.class,CachingElConfig.class,MongoElConfig.class,JmsElConfig.class})
public class AppConfig {
}
@Configuration
public class CachingElConfig {
@Autowired
@Qualifier("jedisConnectionFactory")
private JedisConnectionFactory jedisConnectionFactory;
@Autowired
@Qualifier("keySerializer")
private StringRedisSerializer keySerializer;
@Autowired
@Qualifier("valueSerializer")
private JdkSerializationRedisSerializer valueSerializer;
@Bean(name = "redisTemplate")
public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(jedisConnectionFactory);
redisTemplate.setKeySerializer(keySerializer);
redisTemplate.setHashKeySerializer(keySerializer);
redisTemplate.setValueSerializer(valueSerializer);
redisTemplate.setHashValueSerializer(valueSerializer);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
@Bean
public CacheManager cacheManager(RedisTemplate<String, Object> redisTemplate) {
RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
// 設置過期時間
// cacheManager.setDefaultExpiration(10);
return cacheManager;
}
}
@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;
}
}
點擊(此處)折疊或打開
@Configuration
public class JmsElConfig {
@Autowired
@Qualifier("cachingConnectionFactory")
private CachingConnectionFactory cachingConnectionFactory;
@Bean(name = "jmsTemplate")
public JmsTemplate jmsTemplate() {
JmsTemplate jmsTemplate = new JmsTemplate();
jmsTemplate.setConnectionFactory(cachingConnectionFactory);
return jmsTemplate;
}
@Bean(name = "serviceDemoDestination")
public Destination serviceDemoDestination() {
ActiveMQQueue serviceDemoQueue = new ActiveMQQueue("serviceDemoQueue");
return serviceDemoQueue;
}
@Bean(name = "jmsListenerContainerFactory")
public JmsListenerContainerFactory<DefaultMessageListenerContainer> jmsListenerContainerFactory() {
DefaultJmsListenerContainerFactory jmsListenerContainerFactory = new DefaultJmsListenerContainerFactory();
jmsListenerContainerFactory.setConnectionFactory(cachingConnectionFactory);
return jmsListenerContainerFactory;
}
}
點擊(此處)折疊或打開
@Configuration
public class MongoElConfig {
@Autowired
@Qualifier("mongoDbFactory")
private MongoDbFactory mongoDbFactory;
@Autowired
@Qualifier("mongoConverter")
private MongoConverter mongoConverter;
@Bean(name = "mongoTemplate")
public MongoTemplate mongoTemplate() {
MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory, mongoConverter);
return mongoTemplate;
}
}
點擊(此處)折疊或打開
@Configuration
@PropertySource("classpath:systemConfig.properties")
public class SystemElConfig {
@Value("${mail.host}")
private String mailHost;
@Autowired
private Environment environment;
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigure() {
return new PropertySourcesPlaceholderConfigurer();
}
/**
* @return the mailHost
*/
public String getMailHost() {
return mailHost;
}
/**
* @param mailHost
* the mailHost to set
*/
public void setMailHost(String mailHost) {
this.mailHost = mailHost;
}
}
點擊(此處)折疊或打開
@Configuration
@PropertySource("classpath:systemConfig.properties")
public class SystemElConfig {
@Value("${mail.host}")
private String mailHost;
@Autowired
private Environment environment;
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigure() {
return new PropertySourcesPlaceholderConfigurer();
}
/**
* @return the mailHost
*/
public String getMailHost() {
return mailHost;
}
/**
* @param mailHost
* the mailHost to set
*/
public void setMailHost(String mailHost) {
this.mailHost = mailHost;
}
}
點擊(此處)折疊或打開
@Configuration
public class TransactionManagerElConfig {
@Autowired
@Qualifier("platformTomcat")
private DataSource platformTomcat;
@Autowired
@Qualifier("platformReadTomcat")
private DataSource platformReadTomcat;
@Bean(name = "jdbcTemplate")
public JdbcTemplate jdbcTemplate() {
JdbcTemplate jdbcTemplate = new JdbcTemplate();
jdbcTemplate.setDataSource(platformTomcat);
return jdbcTemplate;
}
@Bean(name = "jdbcReadTemplate")
public JdbcTemplate jdbcReadTemplate() {
JdbcTemplate jdbcReadTemplate = new JdbcTemplate();
jdbcReadTemplate.setDataSource(platformReadTomcat);
return jdbcReadTemplate;
}
@Bean(name = "transactionManager")
public DataSourceTransactionManager transactionManager() {
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
transactionManager.setDataSource(platformTomcat);
return transactionManager;
}
}
四:Demo
點擊(此處)折疊或打開
public class App {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
System.out.println(null == context.getBean("platformTomcat"));
System.out.println(null == context.getBean("transactionManager"));
System.out.println(null == context.getBean("redisTemplate"));
System.out.println(null == context.getBean("mongoTemplate"));
System.out.println(null == context.getBean("jmsTemplate"));
System.out.println(context.getBean(SystemElConfig.class).getMailHost());
context.getBean(ServiceDemo.class).print();
}
}
點擊(此處)折疊或打開
@Service
public class ServiceDemo {
@Value("#{systemElConfig.mailHost}")
private String mailHost;
public void print() {
System.out.println("=======" + mailHost);
}
}
點擊(此處)折疊或打開
@Service
public class ServiceDemo {
@Value("#{systemElConfig.mailHost}")
private String mailHost;
public void print() {
System.out.println("=======" + mailHost);
}
}
點擊(此處)折疊或打開
@Service
public class ServiceDemo {
@Value("#{systemElConfig.mailHost}")
private String mailHost;
public void print() {
System.out.println("=======" + mailHost);
}
}
點擊(此處)折疊或打開
@Component
@EnableJms
public class ServiceDemoListener extends AbstractListener {
@JmsListener(containerFactory = "jmsListenerContainerFactory", destination = "serviceDemoQueue")
public void onMessage(Message message) {
try {
if (message instanceof ObjectMessage) {
}
}
catch (Exception e) {
logger.error("消息處理異常", e);
}
}
}
點擊(此處)折疊或打開
@Component
@EnableJms
public class ServiceDemoListener extends AbstractListener {
@JmsListener(containerFactory = "jmsListenerContainerFactory", destination = "serviceDemoQueue")
public void onMessage(Message message) {
try {
if (message instanceof ObjectMessage) {
}
}
catch (Exception e) {
logger.error("消息處理異常", e);
}
}
}
點擊(此處)折疊或打開
@Component
public class ServiceDemoSchedule {
@Autowired
private GmcSmsInfoBo gmcSmsInfoBo;
@Scheduled(cron = "0 0/1 * * * ?")
public void work() {
System.out.println("========Good byte!!=======");
GmcSmsInfo smsInfo = new GmcSmsInfo();
smsInfo.setChannel("test");
smsInfo.setContent("test");
smsInfo.setStatus("01");
smsInfo.setCreateDate(Calendar.getInstance().getTime());
smsInfo.setMobile("99999999999");
try {
gmcSmsInfoBo.add(smsInfo);
System.out.println(null==gmcSmsInfoBo.query(11386));
System.out.println(null==gmcSmsInfoBo.query(11401));
}
catch (BusinessServiceException e) {
e.printStackTrace();
}
}
}
@Service("gmcSmsInfoBo")
public class GmcSmsInfoBo extends AbstractBusinessObject {
@Autowired
private GmcSmsInfoDAO gmcSmsInfoDaoImpl;
@CachePut(value = "GmcSmsInfoCache", key = "'GmcSmsInfo_'+#result.smsId")
@Transactional(rollbackFor={Exception.class,RuntimeException.class})
public GmcSmsInfo add(GmcSmsInfo smsInfo) throws BusinessServiceException {
System.out.println("=============add==========");
try {
smsInfo.setSmsId(gmcSmsInfoDaoImpl.save(smsInfo));
}
catch (FrameworkDAOException e) {
throw new BusinessServiceException(e);
}
return smsInfo;
}
@Cacheable(value="GmcSmsInfoCache",key="'GmcSmsInfo_'+#smsId")
public GmcSmsInfo query(Integer smsId) throws BusinessServiceException {
System.out.println("=============query==========");
try {
return gmcSmsInfoDaoImpl.findById(GmcSmsInfo.class, smsId);
}
catch (Exception e) {
throw new BusinessServiceException(e);
}
}
}
到此,相信大家對“Quartz注解方式怎么配置”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。