Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI Spring 3

Im new to spring mvc, earlier I accessed homepage via root package name "localhost/spring", and I cant find out what i'd changed that i got this error. Web.xml:

    <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>

Homepage Controller

@Controller
public class HomeController {

private UserServiceImpl userService;

@Inject
public HomeController(UserServiceImpl userService)
{
    this.userService = userService;
}   

@RequestMapping(value="/")
public String home(Model model) {

    System.out.println("Sdfsd");

    model.addAttribute("users", userService.getUsers());

    return "home";
}

}

servlet-context.xml:

    <annotation-driven />


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

<context:component-scan base-package="by.mvc.dao" />

<beans:bean id="dataSource"
     class="org.apache.commons.dbcp.BasicDataSource"> 
    <beans:property name="driverClassName" value="org.hsqldb.jdbcDriver" />
    <beans:property name="url" value="jdbc:hsqldb:hsql://localhost/user_db" /> 
    <beans:property name="username" value="root" />
    <beans:property name="password" value="root" />
    <beans:property name="initialSize" value="5" />
    <beans:property name="maxActive" value="10" />
</beans:bean>

<beans:bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <beans:property name="dataSource" ref="dataSource" />
    <beans:property name="packagesToScan" value="by.mvc.dao" />
    <beans:property name="hibernateProperties"> 
        <beans:props> 
            <beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</beans:prop> 
        </beans:props> 
    </beans:property> 
</beans:bean>

<beans:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <beans:property name="sessionFactory" ref="sessionFactory"/>
</beans:bean>

<beans:bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver"/>

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

Any ideas? thanks

like image 357
kassie Avatar asked Dec 27 '22 01:12

kassie


1 Answers

I believe the application may not be scanning the package that contains the controllers. I see a dao package being scanned but I assume you wouldn't put your controllers there. In your configuration scan the package with the controllers.

<context:component-scan base-package="by.mvc.spring" />
like image 163
Kevin Bowersox Avatar answered Apr 18 '23 14:04

Kevin Bowersox