Home > front end >  Cannot reach endpoints in Spring App. XML config
Cannot reach endpoints in Spring App. XML config

Time:06-28

I'm trying to understand how Spring exactly works so I've made a simple one-controller app. Probably I forgot something in xml configuration.

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>spring-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>WEB-INF/applicationContext.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring-dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

applicationContext.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean />
        </mvc:message-converters>
    </mvc:annotation-driven>

    <bean />

</beans>

DogsController:

@RestController
@RequestMapping("/dogs")
public class DogsController {
    @GetMapping
    public Collection<Dog> getAll() {
        return DOGS.values();
    }
}

I got 404 in http://localhost:8080/dogs.

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

What's wrong in my config?

CodePudding user response:

IDEA: run/debug configuration -> Deployement -> Application Context. Intellij Idea inserted there a full artifact name. I found my endpoints after I had inserted there just /.

  • Related