2011-12-15 61 views
1

我寫了一個java程序注入spring郵件,按照這裏的說明 - Spring EMail。我寫了一個JUNIT類來測試它。所有這些都是作爲一個更大項目的一部分而發生的,並且這個大型項目是在Oracle虛擬機箱linux centOS機器中開發的。如果我在centOS中運行測試用例,我看到這個異常。我查了一些linux論壇,沒有看到任何與它相關的答案。我認爲我沒有正確地搜索,因爲這是我在VBOX和Linux中遠程開發的第一個項目。請高手幫忙?我確信我的SMTP主機看起來不錯。在centOS Linux中運行的Spring Java Mail程序引發異常

我找到了一些幫助here - sendmail issue in centOS 。 - 和here - spring forums - 但不知道我是否可以按照所有說明

堆棧跟蹤跟隨。

2011-12-14 20:57:35,654 ERROR [main] (AbstractStep.java:212) - Encountered an error executing the step 
java.lang.AssertionError 
    at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2120) 
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1912) 
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638) 
    at javax.mail.Service.connect(Service.java:248) 
    at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:389) 
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:306) 
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:296) 
    at com.vzwcorp.legal.batch.core.ReportGenerator.write(ReportGenerator.java:67) 
    at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:171) 
    at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:150) 
    at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:268) 
    at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:194) 
    at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:74) 
    at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:371) 
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130) 
    at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:263) 
    at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76) 
    at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367) 
    at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214) 
    at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143) 
    at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:248) 
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195) 
    at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135) 
    at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61) 
    at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60) 
    at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144) 
    at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124) 
    at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135) 
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281) 
    at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120) 
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48) 
    at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114) 
    at com.vzwcorp.legal.eplm.batch.EplmDeliveryBatchTest.testBatchJob(EplmDeliveryBatchTest.java:33) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) 
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) 
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82) 
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) 
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180) 
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59) 
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:115) 
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:102) 
    at org.apache.maven.surefire.Surefire.run(Surefire.java:180) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350) 
    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021) 
+0

什麼是例外?我只看到一堆棧。你的代碼是什麼樣的?沒有代碼就很難發現錯誤或提出建議。 :) – sarnold 2011-12-15 02:07:59

+0

@sarnold - 我編輯了堆棧跟蹤以顯示異常。但事實是,我從未在我的測試案例中聲稱任何東西。我不明白這個斷言錯誤是什麼。也回答關於我的代碼。作爲最後一步,我有一個運行併發送電子郵件的彈簧批量作業。這發生在去年春季批步 – Shiv 2011-12-15 02:13:53

回答

1

您使用的是什麼版本的JavaMail?你使用的是什麼版本的JDK? 這種異常是否可重現?

您正在運行JavaMail代碼中的斷言錯誤,該錯誤永遠不會發生。 它斷言它擁有當前對象的鎖定。由於方法使得 斷言只從同步方法調用,並且特別是同步的Service.connect方法,這絕不應該發生。

1

你有沒有檢查過你的防火牆設置,也許你的centOS虛擬機不允許訪問郵件服務器?

也是在同一臺機器上的電子郵件服務器作爲centOS或遠程?

1

我遇到了同樣的錯誤。我的配置是(從pom.xml的切口)

<spring-version>3.1.2.RELEASE</spring-version> 

和Java郵件

<dependency> 
     <groupId>javax.mail</groupId> 
     <artifactId>mail</artifactId> 
     <version>1.4.4</version> 
     <type>jar</type> 
     <scope>compile</scope> 
    </dependency> 

我升級到Java郵件後1.4.5問題就消失了。

相關問題