千家信息网

Quartz注解方式怎么配置

发表于:2025-01-18 作者:千家信息网编辑
千家信息网最后更新 2025年01月18日,本篇内容主要讲解"Quartz注解方式怎么配置",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"Quartz注解方式怎么配置"吧!一:目录结构二:统一配置文件
千家信息网最后更新 2025年01月18日Quartz注解方式怎么配置

本篇内容主要讲解"Quartz注解方式怎么配置",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"Quartz注解方式怎么配置"吧!

一:目录结构

二:统一配置文件

context-datasource.properties


  1. workDesk.jdbc.driverclass=com.mysql.jdbc.Driver

  2. workDesk.jdbc.url=jdbc:mysql://10.243.3.18:3306/system?userUnicode=true&characterEncoding=UTF-8

  3. workDesk.jdbc.username=root

  4. workDesk.jdbc.password=$Fortune2015

  5. workDesk.jdbc.poolsize.max=3

  6. workDesk.jdbc.poolsize.min=3

  7. workDesk.jdbc.poolsize.initial=2

  8. workDesk.jdbc.idletime.max=25000

  9. workDesk.jdbc.idleConnectionTestPeriod=18000


  10. #-------workDesk jdbc--------

  11. workDesk.read.jdbc.driverclass=com.mysql.jdbc.Driver

  12. workDesk.read.jdbc.url=jdbc:mysql://10.243.3.18:3306/system?userUnicode=true&characterEncoding=UTF-8

  13. workDesk.read.jdbc.username=root

  14. workDesk.read.jdbc.password=$Fortune2015

  15. workDesk.read.jdbc.poolsize.max=3

  16. workDesk.read.jdbc.poolsize.min=3

  17. workDesk.read.jdbc.poolsize.initial=2

  18. workDesk.read.jdbc.idletime.max=25000

  19. workDesk.read.jdbc.idleConnectionTestPeriod=18000



  20. #--------------redis conf------------

  21. redis.ip=10.243.3.18

  22. redis.port=6379

  23. redis.password=$Fortune2015

  24. redis.default.db=0

  25. redis.timeout=30000


  26. redis.pool.maxActive=1024

  27. redis.pool.maxIdle=200

  28. redis.pool.maxWait=1000

  29. redis.pool.testOnBorrow=true



  30. #------------------jms server-------------

  31. activeMq=failover:(tcp://10.243.3.18:61616,tcp://10.243.3.18:61616)?randomize=false


  32. #--------------mongodb conf------------

  33. mongodb.host=10.243.3.27

  34. mongodb.port=27017

  35. mongodb.database=gmap

  36. mongodb.username=mongodb

  37. mongodb.password=$Fortune2016

systemConfig.properties

点击(此处)折叠或打开

  1. #=======================================================================================


  2. #MailSender Config

  3. #=======================================================================================

  4. mail.host=smtp.mxhichina.com

三:配置文件


  1. @Configuration

  2. @EnableScheduling

  3. @EnableCaching

  4. @EnableTransactionManagement(proxyTargetClass = true)

  5. @ComponentScan("com.gemdale,com.enjoylink")

  6. @Import({DataSourceElConfig.class,TransactionManagerElConfig.class,CachingElConfig.class,MongoElConfig.class,JmsElConfig.class})

  7. public class AppConfig {


  8. }

  1. @Configuration

  2. public class CachingElConfig {


  3. @Autowired

  4. @Qualifier("jedisConnectionFactory")

  5. private JedisConnectionFactory jedisConnectionFactory;


  6. @Autowired

  7. @Qualifier("keySerializer")

  8. private StringRedisSerializer keySerializer;


  9. @Autowired

  10. @Qualifier("valueSerializer")

  11. private JdkSerializationRedisSerializer valueSerializer;


  12. @Bean(name = "redisTemplate")

  13. public RedisTemplate redisTemplate() {

  14. RedisTemplate redisTemplate = new RedisTemplate<>();

  15. redisTemplate.setConnectionFactory(jedisConnectionFactory);

  16. redisTemplate.setKeySerializer(keySerializer);

  17. redisTemplate.setHashKeySerializer(keySerializer);

  18. redisTemplate.setValueSerializer(valueSerializer);

  19. redisTemplate.setHashValueSerializer(valueSerializer);

  20. redisTemplate.afterPropertiesSet();

  21. return redisTemplate;

  22. }


  23. @Bean

  24. public CacheManager cacheManager(RedisTemplate redisTemplate) {

  25. RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);

  26. // 设置过期时间

  27. // cacheManager.setDefaultExpiration(10);

  28. return cacheManager;


  29. }

  30. }


  1. @Configuration

  2. @PropertySource("classpath:context-datasource.properties")

  3. public class DataSourceElConfig {


  4. private static Logger logger = Logger.getLogger(DataSourceElConfig.class);


  5. @Value("${workDesk.jdbc.driverclass}")

  6. private String driverClass;

  7. @Value("${workDesk.jdbc.url}")

  8. private String jdbcUrl;

  9. @Value("${workDesk.jdbc.username}")

  10. private String user;

  11. @Value("${workDesk.jdbc.password}")

  12. private String password;

  13. @Value("${workDesk.jdbc.poolsize.max}")

  14. private int maxPoolSize;

  15. @Value("${workDesk.jdbc.poolsize.min}")

  16. private int minPoolSize;

  17. @Value("${workDesk.jdbc.poolsize.initial}")

  18. private int initialPoolSize;

  19. @Value("${workDesk.jdbc.idletime.max}")

  20. private int maxIdleTime;

  21. @Value("${workDesk.jdbc.idleConnectionTestPeriod}")

  22. private int idleConnectionTestPeriod;


  23. @Value("${workDesk.read.jdbc.driverclass}")

  24. private String readDriverClass;

  25. @Value("${workDesk.read.jdbc.url}")

  26. private String readJdbcUrl;

  27. @Value("${workDesk.read.jdbc.username}")

  28. private String readUser;

  29. @Value("${workDesk.read.jdbc.password}")

  30. private String readPassword;

  31. @Value("${workDesk.read.jdbc.poolsize.max}")

  32. private int readMaxPoolSize;

  33. @Value("${workDesk.read.jdbc.poolsize.min}")

  34. private int readMinPoolSize;

  35. @Value("${workDesk.read.jdbc.poolsize.initial}")

  36. private int readInitialPoolSize;

  37. @Value("${workDesk.read.jdbc.idletime.max}")

  38. private int readMaxIdleTime;

  39. @Value("${workDesk.read.jdbc.idleConnectionTestPeriod}")

  40. private int readIdleConnectionTestPeriod;


  41. @Value("${redis.pool.maxActive}")

  42. private int maxTotal;

  43. @Value("${redis.pool.maxIdle}")

  44. private int maxIdle;

  45. @Value("${redis.pool.maxWait}")

  46. private long maxWaitMillis;


  47. @Value("${redis.ip}")

  48. private String redisIp;

  49. @Value("${redis.port}")

  50. private int redisPort;

  51. @Value("${redis.password}")

  52. private String redisPassword;

  53. @Value("${redis.timeout}")

  54. private int redisTimeout;

  55. @Value("${redis.default.db}")

  56. private int redisDb;


  57. @Value("${mongodb.host}")

  58. private String mongoHost;

  59. @Value("${mongodb.port}")

  60. private int mongoPort;

  61. @Value("${mongodb.database}")

  62. private String mongoUserName;

  63. @Value("${mongodb.username}")

  64. private String mongoDB;

  65. @Value("${mongodb.password}")

  66. private String mongoPassword;


  67. @Value("${activeMq}")

  68. private String activeMq;


  69. @Autowired

  70. private Environment environment;


  71. @Bean

  72. public static PropertySourcesPlaceholderConfigurer propertyConfigure() {

  73. return new PropertySourcesPlaceholderConfigurer();

  74. }


  75. /**

  76. * MySql Master 写库数据源

  77. *

  78. * @return

  79. */

  80. @Bean(name = "platformTomcat", destroyMethod = "close")

  81. public ComboPooledDataSource platformTomcat() {

  82. ComboPooledDataSource dataSource = new ComboPooledDataSource();

  83. try {

  84. dataSource.setDriverClass(driverClass);

  85. }

  86. catch (PropertyVetoException e) {

  87. logger.error("数据源配置,无法找到配置类", e);

  88. }

  89. dataSource.setJdbcUrl(jdbcUrl);

  90. dataSource.setUser(user);

  91. dataSource.setPassword(password);

  92. dataSource.setMaxPoolSize(maxPoolSize);

  93. dataSource.setMinPoolSize(minPoolSize);

  94. dataSource.setInitialPoolSize(initialPoolSize);

  95. dataSource.setMaxIdleTime(maxIdleTime);

  96. dataSource.setTestConnectionOnCheckin(true);

  97. dataSource.setPreferredTestQuery("SELECT 1");

  98. dataSource.setIdleConnectionTestPeriod(idleConnectionTestPeriod);

  99. return dataSource;

  100. }


  101. /**

  102. * MySql Slave 读库数据源

  103. *

  104. * @return

  105. */

  106. @Bean(name = "platformReadTomcat", destroyMethod = "close")

  107. public ComboPooledDataSource platformReadTomcat() {

  108. ComboPooledDataSource dataSource = new ComboPooledDataSource();

  109. try {

  110. dataSource.setDriverClass(readDriverClass);

  111. }

  112. catch (PropertyVetoException e) {

  113. logger.error("数据源配置,无法找到配置类", e);

  114. }

  115. dataSource.setJdbcUrl(readJdbcUrl);

  116. dataSource.setUser(readUser);

  117. dataSource.setPassword(readPassword);

  118. dataSource.setMaxPoolSize(readMaxPoolSize);

  119. dataSource.setMinPoolSize(readMinPoolSize);

  120. dataSource.setInitialPoolSize(readInitialPoolSize);

  121. dataSource.setMaxIdleTime(readMaxIdleTime);

  122. dataSource.setTestConnectionOnCheckin(true);

  123. dataSource.setPreferredTestQuery("SELECT 1");

  124. dataSource.setIdleConnectionTestPeriod(readIdleConnectionTestPeriod);

  125. return dataSource;

  126. }


  127. /**

  128. * Redis 连接池配置信息

  129. *

  130. * @return

  131. */

  132. @Bean(name = "jedisPoolConfig")

  133. public JedisPoolConfig jedisPoolConfig() {

  134. JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();

  135. jedisPoolConfig.setMaxTotal(maxTotal);

  136. jedisPoolConfig.setMaxIdle(maxIdle);

  137. jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);

  138. jedisPoolConfig.setTestOnBorrow(true);

  139. return jedisPoolConfig;

  140. }


  141. @Bean(name = "jedisConnectionFactory")

  142. public JedisConnectionFactory jedisConnectionFactory(JedisPoolConfig jedisPoolConfig) {

  143. JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(jedisPoolConfig);

  144. jedisConnectionFactory.setUsePool(true);

  145. jedisConnectionFactory.setHostName(redisIp);

  146. jedisConnectionFactory.setPort(redisPort);

  147. jedisConnectionFactory.setPassword(redisPassword);

  148. jedisConnectionFactory.setTimeout(redisTimeout);

  149. jedisConnectionFactory.setDatabase(redisDb);

  150. jedisConnectionFactory.afterPropertiesSet();

  151. return jedisConnectionFactory;

  152. }


  153. @Bean(name = "keySerializer")

  154. public StringRedisSerializer keySerializer() {

  155. return new StringRedisSerializer();

  156. }


  157. @Bean(name = "valueSerializer")

  158. public JdkSerializationRedisSerializer valueSerializer() {

  159. return new JdkSerializationRedisSerializer();

  160. }


  161. /**

  162. * MongoDB 配置

  163. *

  164. * @return

  165. */

  166. @Bean(name = "mongoDbFactory")

  167. public MongoDbFactory mongoDbFactory() throws Exception {


  168. MongoCredential credential = MongoCredential.createCredential(mongoUserName, mongoDB,

  169. mongoPassword.toCharArray());

  170. ServerAddress serverAddress = new ServerAddress(mongoHost, mongoPort);

  171. MongoClient mongoClient = new MongoClient(serverAddress, Arrays.asList(credential));

  172. SimpleMongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(mongoClient, mongoDB);

  173. return mongoDbFactory;

  174. }


  175. @Bean(name="mongoConverter")

  176. public MongoConverter mongoConverter(MongoDbFactory mongoDbFactory) {


  177. MappingMongoConverter mongoConverter = new MappingMongoConverter(new DefaultDbRefResolver(mongoDbFactory),

  178. new MongoMappingContext());

  179. // 不插入_class

  180. mongoConverter.setTypeMapper(new DefaultMongoTypeMapper(null));

  181. return mongoConverter;

  182. }



  183. /**

  184. * Jms 配置

  185. * @return

  186. */

  187. @Bean(name="activeMQConnectionFactory")

  188. public ActiveMQConnectionFactory activeMQConnectionFactory()

  189. {

  190. ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();

  191. activeMQConnectionFactory.setUseAsyncSend(false);

  192. activeMQConnectionFactory.setBrokerURL(activeMq);

  193. return activeMQConnectionFactory;

  194. }


  195. @Bean(name="cachingConnectionFactory")

  196. public CachingConnectionFactory cachingConnectionFactory(ActiveMQConnectionFactory targetConnectionFactory)

  197. {

  198. CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(targetConnectionFactory);

  199. cachingConnectionFactory.setSessionCacheSize(10);

  200. return cachingConnectionFactory;

  201. }

  202. }

点击(此处)折叠或打开

  1. @Configuration

  2. @PropertySource("classpath:context-datasource.properties")

  3. public class DataSourceElConfig {


  4. private static Logger logger = Logger.getLogger(DataSourceElConfig.class);


  5. @Value("${workDesk.jdbc.driverclass}")

  6. private String driverClass;

  7. @Value("${workDesk.jdbc.url}")

  8. private String jdbcUrl;

  9. @Value("${workDesk.jdbc.username}")

  10. private String user;

  11. @Value("${workDesk.jdbc.password}")

  12. private String password;

  13. @Value("${workDesk.jdbc.poolsize.max}")

  14. private int maxPoolSize;

  15. @Value("${workDesk.jdbc.poolsize.min}")

  16. private int minPoolSize;

  17. @Value("${workDesk.jdbc.poolsize.initial}")

  18. private int initialPoolSize;

  19. @Value("${workDesk.jdbc.idletime.max}")

  20. private int maxIdleTime;

  21. @Value("${workDesk.jdbc.idleConnectionTestPeriod}")

  22. private int idleConnectionTestPeriod;


  23. @Value("${workDesk.read.jdbc.driverclass}")

  24. private String readDriverClass;

  25. @Value("${workDesk.read.jdbc.url}")

  26. private String readJdbcUrl;

  27. @Value("${workDesk.read.jdbc.username}")

  28. private String readUser;

  29. @Value("${workDesk.read.jdbc.password}")

  30. private String readPassword;

  31. @Value("${workDesk.read.jdbc.poolsize.max}")

  32. private int readMaxPoolSize;

  33. @Value("${workDesk.read.jdbc.poolsize.min}")

  34. private int readMinPoolSize;

  35. @Value("${workDesk.read.jdbc.poolsize.initial}")

  36. private int readInitialPoolSize;

  37. @Value("${workDesk.read.jdbc.idletime.max}")

  38. private int readMaxIdleTime;

  39. @Value("${workDesk.read.jdbc.idleConnectionTestPeriod}")

  40. private int readIdleConnectionTestPeriod;


  41. @Value("${redis.pool.maxActive}")

  42. private int maxTotal;

  43. @Value("${redis.pool.maxIdle}")

  44. private int maxIdle;

  45. @Value("${redis.pool.maxWait}")

  46. private long maxWaitMillis;


  47. @Value("${redis.ip}")

  48. private String redisIp;

  49. @Value("${redis.port}")

  50. private int redisPort;

  51. @Value("${redis.password}")

  52. private String redisPassword;

  53. @Value("${redis.timeout}")

  54. private int redisTimeout;

  55. @Value("${redis.default.db}")

  56. private int redisDb;


  57. @Value("${mongodb.host}")

  58. private String mongoHost;

  59. @Value("${mongodb.port}")

  60. private int mongoPort;

  61. @Value("${mongodb.database}")

  62. private String mongoUserName;

  63. @Value("${mongodb.username}")

  64. private String mongoDB;

  65. @Value("${mongodb.password}")

  66. private String mongoPassword;


  67. @Value("${activeMq}")

  68. private String activeMq;


  69. @Autowired

  70. private Environment environment;


  71. @Bean

  72. public static PropertySourcesPlaceholderConfigurer propertyConfigure() {

  73. return new PropertySourcesPlaceholderConfigurer();

  74. }


  75. /**

  76. * MySql Master 写库数据源

  77. *

  78. * @return

  79. */

  80. @Bean(name = "platformTomcat", destroyMethod = "close")

  81. public ComboPooledDataSource platformTomcat() {

  82. ComboPooledDataSource dataSource = new ComboPooledDataSource();

  83. try {

  84. dataSource.setDriverClass(driverClass);

  85. }

  86. catch (PropertyVetoException e) {

  87. logger.error("数据源配置,无法找到配置类", e);

  88. }

  89. dataSource.setJdbcUrl(jdbcUrl);

  90. dataSource.setUser(user);

  91. dataSource.setPassword(password);

  92. dataSource.setMaxPoolSize(maxPoolSize);

  93. dataSource.setMinPoolSize(minPoolSize);

  94. dataSource.setInitialPoolSize(initialPoolSize);

  95. dataSource.setMaxIdleTime(maxIdleTime);

  96. dataSource.setTestConnectionOnCheckin(true);

  97. dataSource.setPreferredTestQuery("SELECT 1");

  98. dataSource.setIdleConnectionTestPeriod(idleConnectionTestPeriod);

  99. return dataSource;

  100. }


  101. /**

  102. * MySql Slave 读库数据源

  103. *

  104. * @return

  105. */

  106. @Bean(name = "platformReadTomcat", destroyMethod = "close")

  107. public ComboPooledDataSource platformReadTomcat() {

  108. ComboPooledDataSource dataSource = new ComboPooledDataSource();

  109. try {

  110. dataSource.setDriverClass(readDriverClass);

  111. }

  112. catch (PropertyVetoException e) {

  113. logger.error("数据源配置,无法找到配置类", e);

  114. }

  115. dataSource.setJdbcUrl(readJdbcUrl);

  116. dataSource.setUser(readUser);

  117. dataSource.setPassword(readPassword);

  118. dataSource.setMaxPoolSize(readMaxPoolSize);

  119. dataSource.setMinPoolSize(readMinPoolSize);

  120. dataSource.setInitialPoolSize(readInitialPoolSize);

  121. dataSource.setMaxIdleTime(readMaxIdleTime);

  122. dataSource.setTestConnectionOnCheckin(true);

  123. dataSource.setPreferredTestQuery("SELECT 1");

  124. dataSource.setIdleConnectionTestPeriod(readIdleConnectionTestPeriod);

  125. return dataSource;

  126. }


  127. /**

  128. * Redis 连接池配置信息

  129. *

  130. * @return

  131. */

  132. @Bean(name = "jedisPoolConfig")

  133. public JedisPoolConfig jedisPoolConfig() {

  134. JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();

  135. jedisPoolConfig.setMaxTotal(maxTotal);

  136. jedisPoolConfig.setMaxIdle(maxIdle);

  137. jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);

  138. jedisPoolConfig.setTestOnBorrow(true);

  139. return jedisPoolConfig;

  140. }


  141. @Bean(name = "jedisConnectionFactory")

  142. public JedisConnectionFactory jedisConnectionFactory(JedisPoolConfig jedisPoolConfig) {

  143. JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(jedisPoolConfig);

  144. jedisConnectionFactory.setUsePool(true);

  145. jedisConnectionFactory.setHostName(redisIp);

  146. jedisConnectionFactory.setPort(redisPort);

  147. jedisConnectionFactory.setPassword(redisPassword);

  148. jedisConnectionFactory.setTimeout(redisTimeout);

  149. jedisConnectionFactory.setDatabase(redisDb);

  150. jedisConnectionFactory.afterPropertiesSet();

  151. return jedisConnectionFactory;

  152. }


  153. @Bean(name = "keySerializer")

  154. public StringRedisSerializer keySerializer() {

  155. return new StringRedisSerializer();

  156. }


  157. @Bean(name = "valueSerializer")

  158. public JdkSerializationRedisSerializer valueSerializer() {

  159. return new JdkSerializationRedisSerializer();

  160. }


  161. /**

  162. * MongoDB 配置

  163. *

  164. * @return

  165. */

  166. @Bean(name = "mongoDbFactory")

  167. public MongoDbFactory mongoDbFactory() throws Exception {


  168. MongoCredential credential = MongoCredential.createCredential(mongoUserName, mongoDB,

  169. mongoPassword.toCharArray());

  170. ServerAddress serverAddress = new ServerAddress(mongoHost, mongoPort);

  171. MongoClient mongoClient = new MongoClient(serverAddress, Arrays.asList(credential));

  172. SimpleMongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(mongoClient, mongoDB);

  173. return mongoDbFactory;

  174. }


  175. @Bean(name="mongoConverter")

  176. public MongoConverter mongoConverter(MongoDbFactory mongoDbFactory) {


  177. MappingMongoConverter mongoConverter = new MappingMongoConverter(new DefaultDbRefResolver(mongoDbFactory),

  178. new MongoMappingContext());

  179. // 不插入_class

  180. mongoConverter.setTypeMapper(new DefaultMongoTypeMapper(null));

  181. return mongoConverter;

  182. }



  183. /**

  184. * Jms 配置

  185. * @return

  186. */

  187. @Bean(name="activeMQConnectionFactory")

  188. public ActiveMQConnectionFactory activeMQConnectionFactory()

  189. {

  190. ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();

  191. activeMQConnectionFactory.setUseAsyncSend(false);

  192. activeMQConnectionFactory.setBrokerURL(activeMq);

  193. return activeMQConnectionFactory;

  194. }


  195. @Bean(name="cachingConnectionFactory")

  196. public CachingConnectionFactory cachingConnectionFactory(ActiveMQConnectionFactory targetConnectionFactory)

  197. {

  198. CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(targetConnectionFactory);

  199. cachingConnectionFactory.setSessionCacheSize(10);

  200. return cachingConnectionFactory;

  201. }

  202. }

点击(此处)折叠或打开

  1. @Configuration

  2. public class JmsElConfig {


  3. @Autowired

  4. @Qualifier("cachingConnectionFactory")

  5. private CachingConnectionFactory cachingConnectionFactory;


  6. @Bean(name = "jmsTemplate")

  7. public JmsTemplate jmsTemplate() {

  8. JmsTemplate jmsTemplate = new JmsTemplate();

  9. jmsTemplate.setConnectionFactory(cachingConnectionFactory);

  10. return jmsTemplate;

  11. }


  12. @Bean(name = "serviceDemoDestination")

  13. public Destination serviceDemoDestination() {

  14. ActiveMQQueue serviceDemoQueue = new ActiveMQQueue("serviceDemoQueue");

  15. return serviceDemoQueue;


  16. }


  17. @Bean(name = "jmsListenerContainerFactory")

  18. public JmsListenerContainerFactory jmsListenerContainerFactory() {

  19. DefaultJmsListenerContainerFactory jmsListenerContainerFactory = new DefaultJmsListenerContainerFactory();

  20. jmsListenerContainerFactory.setConnectionFactory(cachingConnectionFactory);

  21. return jmsListenerContainerFactory;

  22. }


  23. }

点击(此处)折叠或打开

  1. @Configuration

  2. public class MongoElConfig {


  3. @Autowired

  4. @Qualifier("mongoDbFactory")

  5. private MongoDbFactory mongoDbFactory;


  6. @Autowired

  7. @Qualifier("mongoConverter")

  8. private MongoConverter mongoConverter;


  9. @Bean(name = "mongoTemplate")

  10. public MongoTemplate mongoTemplate() {

  11. MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory, mongoConverter);

  12. return mongoTemplate;


  13. }


  14. }

点击(此处)折叠或打开

  1. @Configuration

  2. @PropertySource("classpath:systemConfig.properties")

  3. public class SystemElConfig {


  4. @Value("${mail.host}")

  5. private String mailHost;


  6. @Autowired

  7. private Environment environment;


  8. @Bean

  9. public static PropertySourcesPlaceholderConfigurer propertyConfigure() {

  10. return new PropertySourcesPlaceholderConfigurer();

  11. }


  12. /**

  13. * @return the mailHost

  14. */

  15. public String getMailHost() {

  16. return mailHost;

  17. }


  18. /**

  19. * @param mailHost

  20. * the mailHost to set

  21. */

  22. public void setMailHost(String mailHost) {

  23. this.mailHost = mailHost;

  24. }


  25. }

点击(此处)折叠或打开

  1. @Configuration

  2. @PropertySource("classpath:systemConfig.properties")

  3. public class SystemElConfig {


  4. @Value("${mail.host}")

  5. private String mailHost;


  6. @Autowired

  7. private Environment environment;


  8. @Bean

  9. public static PropertySourcesPlaceholderConfigurer propertyConfigure() {

  10. return new PropertySourcesPlaceholderConfigurer();

  11. }


  12. /**

  13. * @return the mailHost

  14. */

  15. public String getMailHost() {

  16. return mailHost;

  17. }


  18. /**

  19. * @param mailHost

  20. * the mailHost to set

  21. */

  22. public void setMailHost(String mailHost) {

  23. this.mailHost = mailHost;

  24. }


  25. }

点击(此处)折叠或打开

  1. @Configuration

  2. public class TransactionManagerElConfig {


  3. @Autowired

  4. @Qualifier("platformTomcat")

  5. private DataSource platformTomcat;


  6. @Autowired

  7. @Qualifier("platformReadTomcat")

  8. private DataSource platformReadTomcat;


  9. @Bean(name = "jdbcTemplate")

  10. public JdbcTemplate jdbcTemplate() {

  11. JdbcTemplate jdbcTemplate = new JdbcTemplate();

  12. jdbcTemplate.setDataSource(platformTomcat);

  13. return jdbcTemplate;

  14. }


  15. @Bean(name = "jdbcReadTemplate")

  16. public JdbcTemplate jdbcReadTemplate() {

  17. JdbcTemplate jdbcReadTemplate = new JdbcTemplate();

  18. jdbcReadTemplate.setDataSource(platformReadTomcat);

  19. return jdbcReadTemplate;

  20. }


  21. @Bean(name = "transactionManager")

  22. public DataSourceTransactionManager transactionManager() {

  23. DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();

  24. transactionManager.setDataSource(platformTomcat);

  25. return transactionManager;

  26. }


  27. }



四:Demo


点击(此处)折叠或打开

  1. public class App {

  2. public static void main(String[] args) {

  3. AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);


  4. System.out.println(null == context.getBean("platformTomcat"));

  5. System.out.println(null == context.getBean("transactionManager"));

  6. System.out.println(null == context.getBean("redisTemplate"));

  7. System.out.println(null == context.getBean("mongoTemplate"));

  8. System.out.println(null == context.getBean("jmsTemplate"));


  9. System.out.println(context.getBean(SystemElConfig.class).getMailHost());


  10. context.getBean(ServiceDemo.class).print();


  11. }

  12. }

点击(此处)折叠或打开

  1. @Service

  2. public class ServiceDemo {


  3. @Value("#{systemElConfig.mailHost}")

  4. private String mailHost;


  5. public void print() {

  6. System.out.println("=======" + mailHost);

  7. }


  8. }

点击(此处)折叠或打开

  1. @Service

  2. public class ServiceDemo {


  3. @Value("#{systemElConfig.mailHost}")

  4. private String mailHost;


  5. public void print() {

  6. System.out.println("=======" + mailHost);

  7. }


  8. }

点击(此处)折叠或打开

  1. @Service

  2. public class ServiceDemo {


  3. @Value("#{systemElConfig.mailHost}")

  4. private String mailHost;


  5. public void print() {

  6. System.out.println("=======" + mailHost);

  7. }


  8. }

点击(此处)折叠或打开

  1. @Component

  2. @EnableJms

  3. public class ServiceDemoListener extends AbstractListener {


  4. @JmsListener(containerFactory = "jmsListenerContainerFactory", destination = "serviceDemoQueue")

  5. public void onMessage(Message message) {


  6. try {

  7. if (message instanceof ObjectMessage) {


  8. }

  9. }

  10. catch (Exception e) {

  11. logger.error("消息处理异常", e);

  12. }

  13. }


  14. }

点击(此处)折叠或打开

  1. @Component

  2. @EnableJms

  3. public class ServiceDemoListener extends AbstractListener {


  4. @JmsListener(containerFactory = "jmsListenerContainerFactory", destination = "serviceDemoQueue")

  5. public void onMessage(Message message) {


  6. try {

  7. if (message instanceof ObjectMessage) {


  8. }

  9. }

  10. catch (Exception e) {

  11. logger.error("消息处理异常", e);

  12. }

  13. }


  14. }

点击(此处)折叠或打开

  1. @Component

  2. public class ServiceDemoSchedule {


  3. @Autowired

  4. private GmcSmsInfoBo gmcSmsInfoBo;


  5. @Scheduled(cron = "0 0/1 * * * ?")

  6. public void work() {

  7. System.out.println("========Good byte!!=======");


  8. GmcSmsInfo smsInfo = new GmcSmsInfo();

  9. smsInfo.setChannel("test");

  10. smsInfo.setContent("test");

  11. smsInfo.setStatus("01");

  12. smsInfo.setCreateDate(Calendar.getInstance().getTime());

  13. smsInfo.setMobile("99999999999");


  14. try {

  15. gmcSmsInfoBo.add(smsInfo);


  16. System.out.println(null==gmcSmsInfoBo.query(11386));

  17. System.out.println(null==gmcSmsInfoBo.query(11401));

  18. }

  19. catch (BusinessServiceException e) {

  20. e.printStackTrace();

  21. }


  22. }


  23. }

  1. @Service("gmcSmsInfoBo")

  2. public class GmcSmsInfoBo extends AbstractBusinessObject {


  3. @Autowired

  4. private GmcSmsInfoDAO gmcSmsInfoDaoImpl;


  5. @CachePut(value = "GmcSmsInfoCache", key = "'GmcSmsInfo_'+#result.smsId")

  6. @Transactional(rollbackFor={Exception.class,RuntimeException.class})

  7. public GmcSmsInfo add(GmcSmsInfo smsInfo) throws BusinessServiceException {

  8. System.out.println("=============add==========");

  9. try {

  10. smsInfo.setSmsId(gmcSmsInfoDaoImpl.save(smsInfo));

  11. }

  12. catch (FrameworkDAOException e) {

  13. throw new BusinessServiceException(e);

  14. }

  15. return smsInfo;

  16. }


  17. @Cacheable(value="GmcSmsInfoCache",key="'GmcSmsInfo_'+#smsId")

  18. public GmcSmsInfo query(Integer smsId) throws BusinessServiceException {

  19. System.out.println("=============query==========");

  20. try {

  21. return gmcSmsInfoDaoImpl.findById(GmcSmsInfo.class, smsId);

  22. }

  23. catch (Exception e) {

  24. throw new BusinessServiceException(e);

  25. }

  26. }


  27. }

到此,相信大家对"Quartz注解方式怎么配置"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

0