文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Quartz注解方式怎么配置

2023-06-04 13:34

关注

本篇内容主要讲解“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<String, Object> redisTemplate() {

  14.         RedisTemplate<String, Object> 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<String, Object> 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.     

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

  69.     private String activeMq;

  70.     @Autowired

  71.     private Environment environment;

  72.     @Bean

  73.     public static PropertySourcesPlaceholderConfigurer propertyConfigure() {

  74.         return new PropertySourcesPlaceholderConfigurer();

  75.     }

  76.     

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

  78.     public ComboPooledDataSource platformTomcat() {

  79.         ComboPooledDataSource dataSource = new ComboPooledDataSource();

  80.         try {

  81.             dataSource.setDriverClass(driverClass);

  82.         }

  83.         catch (PropertyVetoException e) {

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

  85.         }

  86.         dataSource.setJdbcUrl(jdbcUrl);

  87.         dataSource.setUser(user);

  88.         dataSource.setPassword(password);

  89.         dataSource.setMaxPoolSize(maxPoolSize);

  90.         dataSource.setMinPoolSize(minPoolSize);

  91.         dataSource.setInitialPoolSize(initialPoolSize);

  92.         dataSource.setMaxIdleTime(maxIdleTime);

  93.         dataSource.setTestConnectionOnCheckin(true);

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

  95.         dataSource.setIdleConnectionTestPeriod(idleConnectionTestPeriod);

  96.         return dataSource;

  97.     }

  98.     

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

  100.     public ComboPooledDataSource platformReadTomcat() {

  101.         ComboPooledDataSource dataSource = new ComboPooledDataSource();

  102.         try {

  103.             dataSource.setDriverClass(readDriverClass);

  104.         }

  105.         catch (PropertyVetoException e) {

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

  107.         }

  108.         dataSource.setJdbcUrl(readJdbcUrl);

  109.         dataSource.setUser(readUser);

  110.         dataSource.setPassword(readPassword);

  111.         dataSource.setMaxPoolSize(readMaxPoolSize);

  112.         dataSource.setMinPoolSize(readMinPoolSize);

  113.         dataSource.setInitialPoolSize(readInitialPoolSize);

  114.         dataSource.setMaxIdleTime(readMaxIdleTime);

  115.         dataSource.setTestConnectionOnCheckin(true);

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

  117.         dataSource.setIdleConnectionTestPeriod(readIdleConnectionTestPeriod);

  118.         return dataSource;

  119.     }

  120.     

  121.     @Bean(name = "jedisPoolConfig")

  122.     public JedisPoolConfig jedisPoolConfig() {

  123.         JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();

  124.         jedisPoolConfig.setMaxTotal(maxTotal);

  125.         jedisPoolConfig.setMaxIdle(maxIdle);

  126.         jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);

  127.         jedisPoolConfig.setTestOnBorrow(true);

  128.         return jedisPoolConfig;

  129.     }

  130.     @Bean(name = "jedisConnectionFactory")

  131.     public JedisConnectionFactory jedisConnectionFactory(JedisPoolConfig jedisPoolConfig) {

  132.         JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(jedisPoolConfig);

  133.         jedisConnectionFactory.setUsePool(true);

  134.         jedisConnectionFactory.setHostName(redisIp);

  135.         jedisConnectionFactory.setPort(redisPort);

  136.         jedisConnectionFactory.setPassword(redisPassword);

  137.         jedisConnectionFactory.setTimeout(redisTimeout);

  138.         jedisConnectionFactory.setDatabase(redisDb);

  139.         jedisConnectionFactory.afterPropertiesSet();

  140.         return jedisConnectionFactory;

  141.     }

  142.     @Bean(name = "keySerializer")

  143.     public StringRedisSerializer keySerializer() {

  144.         return new StringRedisSerializer();

  145.     }

  146.     @Bean(name = "valueSerializer")

  147.     public JdkSerializationRedisSerializer valueSerializer() {

  148.         return new JdkSerializationRedisSerializer();

  149.     }

  150.     

  151.     @Bean(name = "mongoDbFactory")

  152.     public MongoDbFactory mongoDbFactory() throws Exception {

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

  154.                 mongoPassword.toCharArray());

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

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

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

  158.         return mongoDbFactory;

  159.     }

  160.     @Bean(name="mongoConverter")

  161.     public MongoConverter mongoConverter(MongoDbFactory mongoDbFactory) {

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

  163.                 new MongoMappingContext());

  164.         // 不插入_class

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

  166.         return mongoConverter;

  167.     }

  168.     

  169.     

  170.     

  171.     @Bean(name="activeMQConnectionFactory")

  172.     public ActiveMQConnectionFactory activeMQConnectionFactory()

  173.     {

  174.         ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();

  175.         activeMQConnectionFactory.setUseAsyncSend(false);

  176.         activeMQConnectionFactory.setBrokerURL(activeMq);

  177.         return activeMQConnectionFactory;

  178.     }

  179.     

  180.     @Bean(name="cachingConnectionFactory")

  181.     public CachingConnectionFactory cachingConnectionFactory(ActiveMQConnectionFactory targetConnectionFactory)

  182.     {

  183.         CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(targetConnectionFactory);

  184.         cachingConnectionFactory.setSessionCacheSize(10);

  185.         return cachingConnectionFactory;

  186.     }

  187. }

点击(此处)折叠或打开

  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.     

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

  69.     private String activeMq;

  70.     @Autowired

  71.     private Environment environment;

  72.     @Bean

  73.     public static PropertySourcesPlaceholderConfigurer propertyConfigure() {

  74.         return new PropertySourcesPlaceholderConfigurer();

  75.     }

  76.     

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

  78.     public ComboPooledDataSource platformTomcat() {

  79.         ComboPooledDataSource dataSource = new ComboPooledDataSource();

  80.         try {

  81.             dataSource.setDriverClass(driverClass);

  82.         }

  83.         catch (PropertyVetoException e) {

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

  85.         }

  86.         dataSource.setJdbcUrl(jdbcUrl);

  87.         dataSource.setUser(user);

  88.         dataSource.setPassword(password);

  89.         dataSource.setMaxPoolSize(maxPoolSize);

  90.         dataSource.setMinPoolSize(minPoolSize);

  91.         dataSource.setInitialPoolSize(initialPoolSize);

  92.         dataSource.setMaxIdleTime(maxIdleTime);

  93.         dataSource.setTestConnectionOnCheckin(true);

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

  95.         dataSource.setIdleConnectionTestPeriod(idleConnectionTestPeriod);

  96.         return dataSource;

  97.     }

  98.     

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

  100.     public ComboPooledDataSource platformReadTomcat() {

  101.         ComboPooledDataSource dataSource = new ComboPooledDataSource();

  102.         try {

  103.             dataSource.setDriverClass(readDriverClass);

  104.         }

  105.         catch (PropertyVetoException e) {

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

  107.         }

  108.         dataSource.setJdbcUrl(readJdbcUrl);

  109.         dataSource.setUser(readUser);

  110.         dataSource.setPassword(readPassword);

  111.         dataSource.setMaxPoolSize(readMaxPoolSize);

  112.         dataSource.setMinPoolSize(readMinPoolSize);

  113.         dataSource.setInitialPoolSize(readInitialPoolSize);

  114.         dataSource.setMaxIdleTime(readMaxIdleTime);

  115.         dataSource.setTestConnectionOnCheckin(true);

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

  117.         dataSource.setIdleConnectionTestPeriod(readIdleConnectionTestPeriod);

  118.         return dataSource;

  119.     }

  120.     

  121.     @Bean(name = "jedisPoolConfig")

  122.     public JedisPoolConfig jedisPoolConfig() {

  123.         JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();

  124.         jedisPoolConfig.setMaxTotal(maxTotal);

  125.         jedisPoolConfig.setMaxIdle(maxIdle);

  126.         jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);

  127.         jedisPoolConfig.setTestOnBorrow(true);

  128.         return jedisPoolConfig;

  129.     }

  130.     @Bean(name = "jedisConnectionFactory")

  131.     public JedisConnectionFactory jedisConnectionFactory(JedisPoolConfig jedisPoolConfig) {

  132.         JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(jedisPoolConfig);

  133.         jedisConnectionFactory.setUsePool(true);

  134.         jedisConnectionFactory.setHostName(redisIp);

  135.         jedisConnectionFactory.setPort(redisPort);

  136.         jedisConnectionFactory.setPassword(redisPassword);

  137.         jedisConnectionFactory.setTimeout(redisTimeout);

  138.         jedisConnectionFactory.setDatabase(redisDb);

  139.         jedisConnectionFactory.afterPropertiesSet();

  140.         return jedisConnectionFactory;

  141.     }

  142.     @Bean(name = "keySerializer")

  143.     public StringRedisSerializer keySerializer() {

  144.         return new StringRedisSerializer();

  145.     }

  146.     @Bean(name = "valueSerializer")

  147.     public JdkSerializationRedisSerializer valueSerializer() {

  148.         return new JdkSerializationRedisSerializer();

  149.     }

  150.     

  151.     @Bean(name = "mongoDbFactory")

  152.     public MongoDbFactory mongoDbFactory() throws Exception {

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

  154.                 mongoPassword.toCharArray());

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

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

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

  158.         return mongoDbFactory;

  159.     }

  160.     @Bean(name="mongoConverter")

  161.     public MongoConverter mongoConverter(MongoDbFactory mongoDbFactory) {

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

  163.                 new MongoMappingContext());

  164.         // 不插入_class

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

  166.         return mongoConverter;

  167.     }

  168.     

  169.     

  170.     

  171.     @Bean(name="activeMQConnectionFactory")

  172.     public ActiveMQConnectionFactory activeMQConnectionFactory()

  173.     {

  174.         ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();

  175.         activeMQConnectionFactory.setUseAsyncSend(false);

  176.         activeMQConnectionFactory.setBrokerURL(activeMq);

  177.         return activeMQConnectionFactory;

  178.     }

  179.     

  180.     @Bean(name="cachingConnectionFactory")

  181.     public CachingConnectionFactory cachingConnectionFactory(ActiveMQConnectionFactory targetConnectionFactory)

  182.     {

  183.         CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(targetConnectionFactory);

  184.         cachingConnectionFactory.setSessionCacheSize(10);

  185.         return cachingConnectionFactory;

  186.     }

  187. }

点击(此处)折叠或打开

  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<DefaultMessageListenerContainer> 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.     public String getMailHost() {

  14.         return mailHost;

  15.     }

  16.     

  17.     public void setMailHost(String mailHost) {

  18.         this.mailHost = mailHost;

  19.     }

  20. }

点击(此处)折叠或打开

  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.     public String getMailHost() {

  14.         return mailHost;

  15.     }

  16.     

  17.     public void setMailHost(String mailHost) {

  18.         this.mailHost = mailHost;

  19.     }

  20. }

点击(此处)折叠或打开

  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.         }

  11.         catch (Exception e) {

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

  13.         }

  14.     }

  15. }

点击(此处)折叠或打开

  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.         }

  11.         catch (Exception e) {

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

  13.         }

  14.     }

  15. }

点击(此处)折叠或打开

  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.             

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

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

  19.         }

  20.         catch (BusinessServiceException e) {

  21.             e.printStackTrace();

  22.         }

  23.     }

  24. }

  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注解方式怎么配置”有了更深的了解,不妨来实际操作一番吧!这里是编程网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯