mrvrs123
mrvrs123

Reputation: 53

Spring junit NoSuchMethodException

getting below error for my junit test case. can anyone please suggest what i should do to clear this error. I am using maven build tool with the spring 4.3.2 and junit 4.12.

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: [org.springframework.test.context.web.ServletTestExecutionListener@691f36, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@18020cc, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@e94e92, org.springframework.test.context.support.DirtiesContextTestExecutionListener@12558d6, org.springframework.test.context.transaction.TransactionalTestExecutionListener@eb7859, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@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 org.springframework.context.support.GenericApplicationContext@df8f5e: 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.springframework.test.context.support.DependencyInjectionTestExecutionListener@e94e92] to prepare test instance [com.bt.dnp.ldap.util.LdapSyncTest@9505f]
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 : i am using 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", "Tcs@12345");
    }
}

Upvotes: 1

Views: 5125

Answers (2)

AmitG
AmitG

Reputation: 609

The cause of this problem is clear: 1. Incorrect Spring jar version. below 4.0 or 2. Multiple jar version in classpath. Some Old version is also present and hence conflicting it. 3. You need a Clean build. may be everything is right but a fresh build is required.

Upvotes: 0

alexbt
alexbt

Reputation: 17025

Try adding this to your pom:

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

Your error shows that spring-context is trying to call spring-aop's ScopedProxyUtils.isScopedTarget(String beanName).

That method is present in 4.3.2 (since 2.5), this can only means that spring-aop's runtime dependency is wrong.

Before adding the dependency above, you may go in a console and type type mvn dependency:tree -Dincludes=org.springframework:spring-aop, you'll find where the wrong version was coming from.

Upvotes: 3

Related Questions