1

I'm trying configure and run spring rest service. I use java configuration, without web.xml file. I receive permanent warning message after successfully deployment application on tomcat:

26-Jul-2015 21:50:09.885 WARNING [http-nio-8080-exec-5] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/context/] in DispatcherServlet with name 'dispatcher' 26-Jul-2015 21:50:10.401 WARNING [http-nio-8080-exec-8] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/context/] in DispatcherServlet with name 'dispatcher' 26-Jul-2015 21:50:10.920 WARNING [http-nio-8080-exec-9] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/context/] in DispatcherServlet with name 'dispatcher'

my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>black-jack</groupId>
<artifactId>com.nikolay</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
    <java.version>1.7</java.version>
    <org.springframework.version>4.1.7.RELEASE</org.springframework.version>
</properties>

<dependencies>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>


    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>


    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.6.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.6.0</version>
    </dependency>



    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.6</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Main application initializer with

    package com.exam.blackjack.config;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class<?>[]{};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class<?>[]{WebConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}

Controller class:

    package com.exam.blackjack.rest.controller;

import com.exam.blackjack.card.Card;
import com.exam.blackjack.card.CardOwner;
import com.exam.blackjack.deck.DeckOperations;
import com.exam.blackjack.rest.container.ParlayRequest;
import com.exam.blackjack.rest.container.response.DealCardsResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import static org.springframework.web.bind.annotation.RequestMethod.POST;

@Controller
@RequestMapping(value = "/blackjack")
public class AppController {

    private LinkedList<Card> deck = null;
    private DeckOperations operations = new DeckOperations();

    private void initDeck() {
        if (deck == null) {
            Card[] cards = DeckOperations.createDeck();
            deck = (LinkedList<Card>) operations.shuffle(cards);
        }
    }

    @RequestMapping(value = "/parlay", method = POST)
    public DealCardsResponse makeRate(ParlayRequest request) {
        //validate request
        initDeck();
        DealCardsResponse response = new DealCardsResponse();
        //blah-blah
        return response;
    }
}

How to avoid this annoying warning message? Googling doesn't help me.

UPD

WebConfig class:

 @EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

    @Bean
    public AppController appController() {
        return new AppController();
    }
}
Nikolas
  • 2,322
  • 9
  • 33
  • 55
  • add your `WebConfig.java` class – Nikolay Rusev Jul 27 '15 at 06:46
  • Well, you're sending a request to `/context/`, and have no controller mapped to this path, so what is surprising? – JB Nizet Jul 27 '15 at 16:37
  • I assume the /context - is the path on the tomcat-server where will be my application. and I will be able make a request under path: localhost:8080/context/blackjack/parlay – Nikolas Jul 27 '15 at 17:02
  • Maybe it's a bug in Intellij IDEA, like in [this post](http://stackoverflow.com/questions/28536718/spring-warning-request-method-head-not-supported) – Nikolas Jul 27 '15 at 17:12
  • This issue was solved with installation of updated version of Intellij IDEA. After this warning message appears only once. – Nikolas Aug 01 '15 at 18:07
  • @BalusC , whose question was the first? – Nikolas Jan 19 '17 at 16:41

0 Answers0