2016-09-07 8 views
1

私のjunitテストケースでは、以下のエラーが表示されます。誰でもこのエラーをクリアするために何をすべきかを提案してください。私はMavenビルドツールをSpring 4.3.2とJUNIT 4.12で使用しています。Spring junit NoSuchMethodException

org.springframework.test.context.support.AbstractTestContextBootstrapper getDefaultTestExecutionListenerClassNames 
INFO: Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] 
07-Sep-2016 18:19:17 org.springframework.test.context.support.AbstractTestContextBootstrapper getTestExecutionListeners 
INFO: Using TestExecutionListeners: [or[email protected]691f36, org.springframework.test[email protected]18020cc, org.springframewor[email protected]e94e92, org.springfra[email protected]12558d6, org.springframew[email protected]eb7859, org.sp[email protected]12a54f9] 
07-Sep-2016 18:19:18 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 
INFO: Loading XML bean definitions from class path resource [testContext.xml] 
07-Sep-2016 18:19:18 org.springframework.context.support.AbstractApplicationContext prepareRefresh 
INFO: Refreshing [email protected]8f5e: startup date [Wed Sep 07 18:19:18 IST 2016]; root of context hierarchy 
07-Sep-2016 18:19:18 org.springframework.core.io.support.PropertiesLoaderSupport loadProperties 
INFO: Loading properties file from class path resource [ldap_DEV.properties] 
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 
SLF4J: Defaulting to no-operation (NOP) logger implementation 
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 
07-Sep-2016 18:19:18 org.springframework.test.context.TestContextManager prepareTestInstance 
SEVERE: Caught exception while allowing TestExecutionListener [org.springframewor[email protected]e94e92] to prepare test instance [[email protected]] 
java.lang.NoSuchMethodError: org.springframework.aop.scope.ScopedProxyUtils.isScopedTarget(Ljava/lang/String;)Z 
    at org.springframework.context.event.EventListenerMethodProcessor.afterSingletonsInstantiated(EventListenerMethodProcessor.java:79) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:796) 
    at 

my java class:私はJava 1.8を使用しています。

import java.io.UnsupportedEncodingException; 
import javax.naming.NamingException; 
import org.junit.After; 
import org.junit.Before; 
import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.ldap.core.LdapTemplate; 
import org.springframework.test.context.ContextConfiguration; 
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration("classpath:testContext.xml") 
public class LdapSyncTest { 
    private LdapSync ldapSync = null; 

    @Autowired 
    private LdapTemplate ldapTemplate; 

    @Before 
    public void init() { 
     ldapSync = new LdapSync(); 
     ldapSync.setLdapTemplate(ldapTemplate); 
    } 

    @Test 
    public void testPasswordSync() throws UnsupportedEncodingException, NamingException { 
     ldapSync.doPwdUpdate("[email protected]", "uid", "BTCOM", "[email protected]"); 
    } 
} 
+0

isScopedTargetは、Springの全バージョンではありません。ここで確認してください:http://docs.spring.io/spring-framework/docs/2.5.x/api/org/springframework/aop/scope/ScopedProxyUtils.htmlそしてここhttp://docs.spring.io/spring/ docs/current/javadoc-api/org/springframework/aop/scope/ScopedProxyUtils.html質問は、どのビルドツールを使用していますか? Maven?あなたのプロジェクトで使用したいスプリングの良いバージョンを使用しているかどうかを確認する必要があります。そして、あなたのコンソール出力をフォーマットしてください、それはこの方法では不可能です。 – Sarseth

+0

私はMaven Sarsethを使用しています – mrvrs123

+0

このツールを使用して、このプロジェクトで使用しているスプリングのバージョンを確認してください:http://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-依存関係tree.htmlとあなたの質問でそれを印刷してください、フォーマットしてください。 – Sarseth

答えて

1

あなたのポンポンにこれを追加してみてください:

<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-aop</artifactId> 
    <version>4.3.2.RELEASE</version> 
</dependency> 

あなたのエラーはspring-contextspring-aopScopedProxyUtils.isScopedTarget(String beanName)を呼び出そうとしていることを示しています。

このメソッドは4.3.2(2.5以降)にあります。これは、spring-aopの実行時依存性が間違っていることを意味します。

上記の依存関係を追加する前に、コンソールに入り、type mvn dependency:tree -Dincludes=org.springframework:spring-aopと入力すると、間違ったバージョンが出ていた が見つかります。

0

この問題の原因は明確です。 1.スプリングジャーのバージョンが正しくありません。 4.0未満 または 2.クラスパスに複数のjarバージョン。いくつかの古いバージョンも存在し、したがってそれを矛盾させます。 3.クリーンビルドが必要です。すべてが正しいかもしれないが、新鮮なビルドが必要です。

関連する問題