您好,登录后才能下订单哦!
本篇内容主要讲解“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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。