0

when i am trying to run the controller Testing in Spring-boot version 1.5.3 Release using the Spring-Boot-Test I am geting the Error Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletException

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit4.SpringRunner;

import com.hanselnpetal.domain.CustomerContact;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
public class ContactsManagementControllerIntegrationTest {

    @Autowired
    ContactsManagementController contactsManagementController;

    @Test
    public void testAddContactHappyPath() {

        CustomerContact aContact = new CustomerContact();
        aContact.setFirstName("Jenny");
        aContact.setLastName("Johnson");

        // POST our CustomerContact form bean to the controller; check the outcome
        String outcome = contactsManagementController.processAddContactSubmit(aContact);

        // Assert THAT the outcome is as expected
        assertThat(outcome, is(equalTo("success")));
    }


}

I am running the class ContactsManagementControllerIntegrationTest.java using (eclipse) the right click on the file and run as junit . any help appreciated.

3
  • do you have servlet api in dependencies? are you user maven or gralde? Commented Jul 12, 2018 at 10:05
  • yes I am using the maven and spring-boot-web-stater which download the spring-boot-starter-tomcat\1.5.3.RELEASE\spring-boot-starter-tomcat-1.5.3.RELEASE.jar D:\mavenrepo\org\apache\tomcat\embed\tomcat-embed-core\8.5.14\tomcat-embed-core-8.5.14.jar D:\mavenrepo\org\apache\tomcat\embed\tomcat-embed-el\8.5.14\tomcat-embed-el-8.5.14.jar D:\mavenrepo\org\apache\tomcat\embed\tomcat-embed-websocket\8.5.14\tomcat-embed-websocket-8.5.14.jar Commented Jul 13, 2018 at 6:37
  • do you have servlet api with provided scope? Commented Jul 13, 2018 at 6:38

1 Answer 1

0

Ensure that you have below dependency in your pom.xml (maven)

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
    <scope>provided</scope>
</dependency>
Sign up to request clarification or add additional context in comments.

2 Comments

Caused by: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.