나는 java/spring/hibernate에 대해 읽었으며 물마루를 "더미"예제로 사용하여 친구에게 내게 조금 더 열심히 추천 할 것을 말했고 지금은 붙어있다. 내가 할 수있는 가장 간단한 클래스가있다. repeadatly 30 초마다 여기, 말할 수 봄 콩에서 metod voice()
를 호출하여 뭔가를 인쇄 할 수있는 가장 간단한 방법은 무엇30 초마다 Java 클래스를 실행하는 가장 간단한 방법은 무엇입니까?
package spring.com.practice;
public class Pitcher {
private String shout;
public String getShout() {
return shout;
}
public void setShout(String shout) {
this.shout = shout;
}
public void voice()
{
System.out.println(getShout());
}
}
생각하고, 그것을하는 것은 내가 지금까지있어 무엇 :
<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="jobSchedulerDetail" />
<property name="startDelay" value="0" />
<property name="repeatInterval" value="30" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="schedulerName" value="pitcherScheduler" />
<property name="triggers">
<list>
<ref bean="simpleTrigger" />
</list>
</property>
</bean>
<bean id="pitcher" class="spring.com.practice.Pitcher">
<property name="shout" value="I started executing..."></property>
</bean>
예, 저는 이것을 Jboss 5에서 실행하려고합니다. 저는 Maven으로 프로젝트를 만들고 있습니다.
나는 몇 가지 제안을했고처럼 내 애플리케이션 컨텍스트는 이제 같습니다12:35:51,657 ERROR [01-SNAPSHOT]] Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
:
<web-app id="simple-webapp" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>spring app</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/conf/applicationContext.xml
</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
지금 나는이 exeption를 얻을 : 여기
<?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:sched="http://www.springinaction.com/schema/sched"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springinaction.com/schema/sched
http://www.springinaction.com/schema/sched-1.0.xsd"
default-lazy-init="true">
<bean id="stuffDoer" class="spring.com.practice">
<property name="shout" value="I'm executing"/>
</bean>
<sched:timer-job
target-bean="stuffDoer"
target-method="voice"
interval="5000"
start-delay="1000"
repeat-count="10" />
</beans>
내 web.xml 파일입니다 나는 30 초마다 hello world와 같은 것을 실행하는 것이 복잡하다는 것을 깨닫지 못했다.
'@ Scheduled' 주석이 정말 멋지게 보입니다. – BalusC
@skaffman 답장을 보내 주셔서 감사합니다. 지금 해보겠습니다. 좀 더 복잡한 작업을 수행하고 싶습니다. 그래서 처음부터 시작하고 싶습니다. "서로 메시지를주고받는 2 개의 객체를 만들고 싶습니다. 하나는 JBossS 5에서 JMS 메시징으로 응답하기 위해 다른 객체를 맞이하고, 30 초마다이 작업을 수행하기를 원합니다."그래서 고려해야 할 첫 번째 작업은 30 초마다 실행되는 작업입니다. 그리고 나서 .. –
@skaffman 훌륭한 대답, 나는 그것을 두 가지 방법으로 모두 시도했다. w00w tnx –