2011-07-07 5 views
1

나는 Quartz 1.8.5 (그리고 역시 Quartz2.0을 사용해 보았다. 같은 문제)를 Spring 3.0.0과 함께 사용하려고한다. 그러나 Quartz 스케줄러, 트리거, 작업에 Spring의 유틸리티 래퍼를 사용하고 싶지 않다. 컨테이너가없는 독립형 Java 애플리케이션에서와 마찬가지로이 모든 객체를 프로그래밍 방식으로 내 애플리케이션에서 만들고 싶다.은 봄에 Quartz Scheduler를 초기화 할 수 없다.

org.quartz.scheduler.instanceName: NotificationsScheduler 
org.quartz.scheduler.instanceId: AUTO 
org.quartz.scheduler.skipUpdateCheck: true 

org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool 
org.quartz.threadPool.threadCount: 3 
org.quartz.threadPool.threadPriority: 5 

org.quartz.jobStore.misfireThreshold: 60000 

org.quartz.jobStore.class: org.quartz.impl.jdbcjobstore.JobStoreTX 
org.quartz.jobStore.driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate 
org.quartz.jobStore.useProperties: false 
org.quartz.jobStore.dataSource: qzDS 
org.quartz.jobStore.tablePrefix: QRTZ_ 
org.quartz.jobStore.isClustered: false 

org.quartz.dataSource.qzDS.driver: com.mysql.jdbc.Driver 
org.quartz.dataSource.qzDS.URL: jdbc:mysql://localhost:3306/myschema 
org.quartz.dataSource.qzDS.user: myuser 
org.quartz.dataSource.qzDS.password: mypwd 
org.quartz.dataSource.qzDS.maxConnections: 5 

그럼, 내가 가진 : 이유가 있지만, 주로

... 내가 동적 트리거와 JobDetails에 대한 요구 사항을 가지고 있기 때문에, 나는 내가 JobStoreTX를 정의하는 클래스 경로에 내 quartz.properties이 단순한 Initializer 클래스. Quartz 배포판의 example1에서 가져온 것임.

public class NotificationInitializer { 

public void init(){ 
try { 
    SchedulerFactory schdFact = new StdSchedulerFactory("quartz.properties"); 
    Scheduler schd = schdFact.getScheduler(); 
    schd.start(); 

    JobDetail jd = new JobDetail("hellojob", Scheduler.DEFAULT_GROUP, HelloJob.class); 
    Trigger t = TriggerUtils.makeImmediateTrigger(2, 1000); 
    t.setStartTime(new Date()); 

    schd.scheduleJob(jd, t); 
    // wait long enough so that the scheduler as an opportunity to run 
    .......... 

    schd.shutdown(true); 
    } catch (SchedulerException e) { 
    ..... 
    } 
} 
} 

그리고 나는 또한이 클래스를 호출하는 간단한 단위 테스트가 :의 같은 예에서 않은 수정 HelloJob을 사용

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations = "classpath:spring/applicationContext.xml") 
public class NotificationInitializerTest { 
    private final static Logger logger = LoggerFactory 
     .getLogger(NotificationInitializerTest.class); 

    @BeforeClass 
    public static void setupClass() { 
     PropertyConfigurator.configure(Loader 
     .getResource("spring/log4j.properties")); 
     PropertyConfigurator.configure(Loader 
      .getResource("spring/quartz.properties")); 
    } 


    @Test 
    public void testInit() { 
     NotificationInitializer ni = new NotificationInitializer(); 
     ni.init(); 
     logger.info("NotificationInitializer.init() finished OK"); 
    } 

} 

을 그리고 나는이 단위 테스트를 실행할 때 난 org.springframework.beans.factory.BeanCreationException :에 의한

: - 다음과 같은 오류가 점점 아래의 전체 스택 추적을 참조 오류 이름으로 콩을 만드는 'org.springframework.jdbc.datasource.init.DataSour ceInitializer 번호 0 ': init 메소드 호출에 실패했습니다. 중첩 예외는 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException : 쿼리가 비어 있습니다.

어떤 문제가 있었나요?

또한 지금은 JobStoreTX를 설정하고 있습니다. 작동하도록하려면 을 입력해야하지만 결국에는 JobStoreCMT를 toSpring의 트랜잭션 관리에 사용하고 싶습니다. 그 방법에 대한 좋은 문서/예제를 찾을 수 없었습니다. 특히 스케줄러에 대한 스프링의 래퍼 및 모든 트리거 정의를 하드 코드화했습니다 ...

감사합니다! 마리나

java.lang.IllegalStateException: Failed to load ApplicationContext 
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308) 
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDeendencies (DependencyInjectionTestExecutionListener.java:109) 
    at org.springframework.test.context.support.Dependenc yInjectionTestExecutionListener.prepareTestInstanc e(DependencyInjectionTestExecutionListener.java:75) 
    at org.springframework.test.context.TestContextManage r.prepareTestInstance(TestContextManager.java:333) 
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.createTest(SpringJUnit4ClassRunner.j ava:220) 
    at 
    ..... 

Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.jdbc.datasource.init.DataSour ceInitializer#0': Invocation of init method failed; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: Query was empty 
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1401) 
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:512) 
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:450) 
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 90) 
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222) 
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:287) 
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:189) 
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:557) 
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:842) 
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:416) 
    at org.springframework.test.context.support.AbstractG enericContextLoader.loadContext(AbstractGenericCon textLoader.java:84) 
    at org.springframework.test.context.support.AbstractG enericContextLoader.loadContext(AbstractGenericCon textLoader.java:1) 
    at org.springframework.test.context.TestContext.loadA pplicationContext(TestContext.java:280) 
    at org.springframework.test.context.TestContext.getAp plicationContext(TestContext.java:304) 
    ... 25 more 

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: Query was empty 
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source) 
    at java.lang.reflect.Constructor.newInstance(Unknown Source) 
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:40 6) 
    at com.mysql.jdbc.Util.getInstance(Util.java:381) 
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:1030) 
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:956) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:3491) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:3423) 
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:19 36) 
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java :2060) 
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionIm pl.java:2536) 
    at com.mysql.jdbc.StatementImpl.executeUpdate(Stateme ntImpl.java:1564) 
    at com.mysql.jdbc.StatementImpl.executeUpdate(Stateme ntImpl.java:1485) 
    at org.apache.commons.dbcp.DelegatingStatement.execut eUpdate(DelegatingStatement.java:228) 
    at org.springframework.jdbc.datasource.init.ResourceD atabasePopulator.executeSqlScript(ResourceDatabase Populator.java:157) 
    at org.springframework.jdbc.datasource.init.ResourceD atabasePopulator.populate(ResourceDatabasePopulato r.java:110) 
    at org.springframework.jdbc.datasource.init.DataSourc eInitializer.afterPropertiesSet(DataSourceInitiali zer.java:69) 
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1460) 
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1398) 
    ... 
+0

스프링 빈 구성을 게시 할 수 있습니까? 봄 응용 프로그램 컨텍스트가로드되는 동안 스크립트를 사용하여 quartz의 DB를 초기화 하시겠습니까? – blob

+0

예, 그것이 이유였습니다! 아래에서 좀 더 자세한 답변을 참조하십시오 ... 감사합니다! – Marina

답변

0

만 추측 : 당신이 연결 검증 쿼리를 지정해야합니다 있는지 확인하십시오. 뭔가 같은 것 validationQuery="select 1"

+0

감사합니다, Ralph, 나는 시도했다 - 그리고 같은 오류가있어 ... – Marina

2

@blob : 당신이 바로 목표물이었습니다. (오류 메시지가 제시했듯이 ....) NotificationInitializer가 초기화되지 않은 이유를 알기 위해 시간을 보냈다. 나는 마지막으로 내 봄 설정에서 Quartz DB 초기화 스크립트를 제거하려고 시도했다 - 모든 것이 매력처럼 작동했다!

<jdbc:initialize-database data-source="dataSource" 
    enabled="${database.initschema}"> 
    <jdbc:script location="${database.schemaLoc}" /> 
    <jdbc:script location="${database.seedLoc}" /> 
    <!-- <jdbc:script location="classpath:db/tables_mysql_innodb_1.8.5.sql" /> --> 
</jdbc:initialize-database> 

난 그냥 내가 석영이 방법을 DB 테이블을 만들 수없는 이유를 난 아직도 이해가 안 돼요, 지금은 ... :) 봄 오류 메시지가 좀 더 구체적인했다

을 기원합니다 - 같은 스크립트를 DB에서 직접 실행할 때 잘 작동합니다. 아마 봄에 시작 액션의 이상한 시퀀스?방법 java.net.InetAddress.getLocalHost() 경우 테스트, 모든

첫째 :

덕분에, 마리나

1

나는 최근에 나를 위해 일한 다음, (나는 맥 OS X에서 Java7를 사용했다)도이 문제를 건너 왔어요 이 예외와 같은 발생하면 작품 :

Caused by: java.net.UnknownHostException: leo-mbp: nodename nor servname provided, or not known 
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) 
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901) 
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293) 
    at java.net.InetAddress.getLocalHost(InetAddress.java:1469) 

실행을 그것을 해결하려면 다음

scutil --set HostName "localhost" 

희망이 있으면 도움이 될 것입니다.

0

quartz.properties 파일에서 "org.quartz.scheduler.instanceId"를 AUTO에서 10으로 변경하면 효과적입니다.

관련 문제