Ruslan
Ruslan

Reputation: 14630

Spring MVC mapping not working: PageNotFound

When i visit localhost:8080/home - i get:

WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/home] in DispatcherServlet with name 'appServlet'

When i visit localhost:8080/ or localhost:8080/index all look ok.

Why one path works, and another don't?

And thing, that confuse me: localhost:8080/homepage.html - return me my home view.


So my project here: https://github.com/IRus/jMusic

my web.xml

<!-- Base servlet handles all requests to the application. -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

servlet-context.xml - i using tiles

<annotation-driven/>

<resources mapping="/resources/**" location="/resources/"/>

<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/"/>
    <beans:property name="suffix" value=".jsp"/>
    <beans:property name="order" value="1" />
</beans:bean>

<beans:import resource="controllers.xml"/>
<beans:import resource="tiles.xml" />
<beans:import resource="i18n.xml"/>
<beans:import resource="themes.xml"/>

tiles.xml

<bean id="tilesviewResolver" class="org.springframework.web.servlet.view.tiles2.TilesViewResolver">
        <property name="order" value="0"/>
</bean>

<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/views/tiles-definitions.xml</value>
        </list>
    </property>
</bean>

ErrorController

@Controller
public class ErrorController {

    @RequestMapping("/403")
    public String error403() {
        return "403";
    }

    @RequestMapping("/404")
    public String error404() {
        return "404";
    }

}

UserController

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/")
    public String index() {
        return "redirect:/index";
    }

    @RequestMapping("/home")
    public String home() {
        return "home";
    }

    @RequestMapping("/login")
    public String login() {
        return "login";
    }

    @RequestMapping("/index")
    public String listUsers(Map<String, Object> map) {

        map.put("user", new User());
        map.put("userList", userService.listUser());

        return "user";
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String addUser(@ModelAttribute("user") User user,
                             BindingResult result) {

        userService.addUser(user);

        return "redirect:/index";
    }

    @RequestMapping("/delete/{idUser}")
    public String deleteUser(@PathVariable("idUser") Long idUser) {

        userService.removeUser(idUser);

        return "redirect:/index";
    }
}

Logs Here: https://gist.github.com/IRus/2ac97c66070001247011

Interested moment in logs:

Mapped URL path [/homepage.html] into handler 'userController' I added, and delete thats @RequestMapping in controller, but it still alive

I work in Idea 12.0.4

Upvotes: 1

Views: 3280

Answers (1)

Ruslan
Ruslan

Reputation: 14630

The problem was in the cache/IDE.

Class file is not updated when I deploy project.

First time i get trouble like this. Just restart IDE and clean tomcat webapps folder(delete my project files from here).

Now everything works as expected.

Upvotes: 2

Related Questions