2012-08-13 3 views
2

기본적으로 타이머로 일부 속성을 검색하려고하지만 속성 빈은 결코 @postconstruct를 호출하지 않기 때문에 널 포인터가 계속 나타납니다. 어떤 아이디어?Singleton bean에 주입되는 ApplicationScoped bean에 의해 postconstruct가 호출되지 않음

DataCaptureTimer.java :

import java.io.File; 
import java.io.Serializable; 

import javax.annotation.PostConstruct; 
import javax.ejb.Schedule; 
import javax.ejb.Singleton; 
import javax.ejb.Startup; 
import javax.enterprise.context.ApplicationScoped; 
import javax.inject.Inject; 
import org.slf4j.Logger; 


@ApplicationScoped 
@Startup 
public class DataCaptureTimer implements Serializable { 

    private static final long serialVersionUID = -1L; 

    @Inject 
    private DataCaptureBP dataCaptureBP; 

    @Inject 
    private transient Logger logger; 

    @Inject 
    private PropertiesBean propertiesBean; 


    private File dataAnalyticsDirectory; 

    @PostConstruct 
    public void setUpDataCaptureTimer(){ 
    } 


    @Schedule(hour = "18", minute = "24") 
    public void automaticProcessing() { 
     if(logger.isInfoEnabled()) { 
      logger.info("Calling DataCapture"); 
     } 

     dataAnalyticsDirectory = new File(propertiesBean.getProperty("gen.data.analytics.directory")); 


     } 

    } 

} 

속성 콩

import java.io.FileInputStream; 
import java.io.IOException; 
import java.util.Properties; 

import javax.annotation.PostConstruct; 
import javax.enterprise.context.ApplicationScoped; 
import javax.inject.Named; 


@ApplicationScoped 
public class PropertiesBean { 

    private static final String SYSTEM_PROPERTIES_NAME = "system.properties"; 

    private Properties props = new Properties(); 

    public PropertiesBean(){ 
    } 

    /** 
    * Loads all the properties from an external props file 
    */ 
    @PostConstruct 
    public void initiateProperties(){ 
     String loc = System.getProperty("jboss.server.config.dir") + "/" + SYSTEM_PROPERTIES_NAME; 
     try { 
      props.load(new FileInputStream(loc)); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 

    /** 
    * Retrieves different system properties by a given key 
    * @param key Key to desired system property 
    * @return String the value of the property with a matching key 
    */ 
    public String getProperty(String key){ 
     return props.getProperty(key); 
    } 
} 

스택 추적

09:19:34,617 ERROR [org.jboss.as.ejb3] (EJB default - 5) JBAS014122: Error during retrying timeout for timer: [id=fd2f6756-8621-4977-9b65-c4110c79a149 timedObjectId=epcfe-web-0.0.1-SNAPSHOT.epcfe-web- 
0.0.1-SNAPSHOT.DataCaptureTimer auto-timer?:true persistent?:true [email protected]eb77f initialExpiration=Tue Aug 14 09:19:00 EDT 2012 intervalDuration(
in milli sec)=0 nextExpiration=Wed Aug 15 09:19:00 EDT 2012 timerState=RETRY_TIMEOUT: javax.ejb.EJBException: java.lang.NullPointerException 
     at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:165) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.as.ejb3.tx.TimerCMTTxInterceptor.handleExceptionInOurTx(TimerCMTTxInterceptor.java:53) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:229) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:303) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:189) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Fin 
al-redhat-1] 
     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:42) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:43) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:102) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.as.ejb3.timerservice.task.CalendarTimerTask.callTimeout(CalendarTimerTask.java:60) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.as.ejb3.timerservice.task.TimerTask.retryTimeout(TimerTask.java:184) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.as.ejb3.timerservice.task.TimerTask.run(TimerTask.java:140) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) [rt.jar:1.6.0_30] 
     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [rt.jar:1.6.0_30] 
     at java.util.concurrent.FutureTask.run(FutureTask.java:138) [rt.jar:1.6.0_30] 
     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_30] 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_30] 
     at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_30] 
     at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.0.0.GA-redhat-1.jar:2.0.0.GA-redhat-1] 
Caused by: java.lang.NullPointerException 
     at java.io.File.<init>(File.java:222) [rt.jar:1.6.0_30] 
     at com.advancestores.storechannel.catalog.presentation.timer.DataCaptureTimer.automaticProcessing(DataCaptureTimer.java:62) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_30] 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_30] 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_30] 
     at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_30] 
     at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72) [jboss-as-ee-7.1.2.F 
inal-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:374) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:129) [jboss-as-weld-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:139) [jboss-as-weld-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:34) [jboss-as-ee-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:34) [jboss-as-ee-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:374) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.as.ejb3.concurrency.ContainerManagedConcurrencyInterceptor.processInvocation(ContainerManagedConcurrencyInterceptor.java:104) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-r 
edhat-1] 
     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:94) [jboss-as-weld-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53) [jboss-as-ee-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.as.ejb3.component.singleton.SingletonComponentInstanceAssociationInterceptor.processInvocation(SingletonComponentInstanceAssociationInterceptor.java:53) [jboss-as-ejb3-7.1.2.Final 
-redhat-1.jar:7.1.2.Final-redhat-1] 
     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1] 
     at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:227) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 
+0

둘 다 @Startup으로 둘 경우 어떻게됩니까? 내 추측으로는 PropertiesBean이 실제로 DataCaptureTimer 빈과 동시에 생성되지 않는다는 것입니다. – LightGuard

답변

0

다시 garding PropertiesBean - 글쎄, 당신은 읽고있는 실제 속성을 절대로 할당하지 못합니다. 그러나 propertiesnew Properties()으로 초기화되므로 절대로 NPE를 던져서는 안됩니다.

실제 스택 추적을 게시 할 수 있습니까?

귀하의 질문에 직접 대답 할지라도. Seam Solder을 사용하면 무료로 자산/자원 주입을받을 수 있습니다. 모양을 가치가있을 수도 ...

관련 문제