Spring framework 을 이용한 scheduling 설정.
1.pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.samples</groupId>
<artifactId>PIPMonitoring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<!-- Generic properties -->
<java.version>1.6</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Spring -->
<spring-framework.version>3.2.3.RELEASE</spring-framework.version>
<!-- Hibernate / JPA -->
<hibernate.version>4.2.1.Final</hibernate.version>
<!-- Logging -->
<logback.version>1.0.13</logback.version>
<slf4j.version>1.7.5</slf4j.version>
<!-- Test -->
<junit.version>4.11</junit.version>
</properties>
<dependencies>
<!-- Spring and Transactions -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<!-- Logging with SLF4J & LogBack -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<scope>runtime</scope>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<!-- Mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
<!--
<dependency>
<groupId>org.apache.ibatis</groupId>
<artifactId>ibatis-sqlmap</artifactId>
<version>2.3.0</version>
</dependency>
-->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<!-- mail library -->
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>dsn</artifactId>
<version>1.4.5</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>gimap</artifactId>
<version>1.4.6-rc1</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>imap</artifactId>
<version>1.4.4</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mailapi</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>pop3</artifactId>
<version>1.4.5-rc1</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>smtp</artifactId>
<version>1.4.5</version>
</dependency>
<!-- Test Artifacts -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring-framework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
</repositories>
</project>
2. applicationContext.xml (디렉토리 : {project home}/resources)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">
<!-- 1. PropertyPlaceholderConfigurer .. property 파일 사용가능하게-->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>file:${properties.home}/pnrmonitor_${pip.monitoring.type}.properties</value>
</property>
</bean>
<import resource="email/EmailConfiguration.xml"/>
<!-- 지정된 패키지에서 빈을 탐색 -->
<context:component-scan base-package="com.xxx.pip.monitor" />
<bean id="dataSourcePIPDB" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.Driver.PIPDB}"/>
<property name="url" value="${db.Url.PIPDB}"/>
<property name="username" value="${db.Username.PIPDB}"/>
<property name="password" value="${db.Password.PIPDB}"/>
</bean>
<bean id="dataSourceAMBIDB" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.Driver.AMBIDB}"/>
<property name="url" value="${db.Url.AMBIDB}"/>
<property name="username" value="${db.Username.AMBIDB}"/>
<property name="password" value="${db.Password.AMBIDB}"/>
</bean>
<!-- 트랜잭션 사용 -->
<!-- <bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSourcePIPDB"></property>
</bean> -->
<bean id="sqlSessionFactoryPIP" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourcePIPDB" />
<property name="mapperLocations" value="classpath:mybatis/mappers/pip/*Mapper_PIP.xml" />
</bean>
<bean id="sqlSessionFactoryAMBI" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourceAMBIDB" />
<property name="mapperLocations" value="classpath:mybatis/mappers/ambi/*Mapper_AMBI.xml" />
</bean>
<!-- 맵퍼 인터페이스와 맵퍼 정의 파일에 의해 생성된 맵퍼 클래스를 빈에 주입 할 수 있도록 함 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.xxx.pip.monitor.mappers.pip" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryPIP" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.xxx.pip.monitor.mappers.ambi" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryAMBI" />
</bean>
<bean id="updateChartData" class="com.xxx.pip.monitor.chart.UpdateOnlineChartData">
<property name="dataFile" value="${chart.datafile}" />
<property name="htmlFile" value="${chart.htmlfile}" />
</bean>
<!-- 미적재 PNR 조회하는 Bean -->
<bean id="missPnrMonitor" class="com.xxx.pip.monitor.misspnr.MissPNRMonitor"/>
<bean id="odsBatcJobMonitor" class="com.xxx.pip.monitor.ods.batch.ODSBatchJobMonitor" />
<!-- Task Scheduler -->
<task:annotation-driven />
<task:scheduled-tasks>
<!-- 스케줄링 : 2분 마다 -->
<task:scheduled ref="missPnrMonitor" method="run" fixed-rate="120000"/>
<!-- 스케줄링 : 매일 1시 -->
<task:scheduled ref="updateChartData" method="run" cron="0 0 1 * * *"/>
<!-- 스케줄링 : 매일 5:45 ~ -->
<task:scheduled ref="odsBatcJobMonitor" method="run" cron="0 45 05-07 * * *"/>
</task:scheduled-tasks>
</beans>
3. 구동 Application java program
package com.xxx.pip.monitor.run;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.asiana.pip.monitor.misspnr.MissPNRMonitor;
public class PIPMonitoringLoader {
public static void main(String[] args) {
// TODO Auto-generated method stub
String springConfig = "classpath*:**/applicationContext*.xml";
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
}
}
4. Java run 환경 변수(VM arguments)
이유는 applicationContext.xml 에서 외부 properties 를 사용하기 때문임.
이렇게 해서 얻는 장점은 window 개발환경과 unix(linux) 개발환경의 디플로이 환경 차이를 극복할 수 있습니다.
아래 pip.monitoring.type=DEV 값을 운영환경에서는 PRD 로 세팅을 하면 됩니다.
그리고 두개의 properties 를 만들어서 관리하면 되겠지요.(pipmonitor_DEV.properties, pipmonitor_PRD.properties)
-Dproperties.home=D:\inho\repository\git\asiana\eclipse\asiana-pip\PIPMonitoring\src\main\resources\conf -Dpip.monitoring.type=DEV
weblogic 12c java.lang.NoSuchMethodError: org.springframework.beans.MutablePropertyValues.add (0) | 2016.05.16 |
---|---|
Spring Mybatis CRUD example (0) | 2016.05.16 |
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for 문제시... (0) | 2014.05.16 |
SpringBatch 에서 외부 parameter 값을 사용할 때. (0) | 2012.09.18 |
[Spring batch] File to DB (0) | 2012.09.04 |
댓글 영역