0

spring-servlet.xml

 <bean
 class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>
<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://127.0.0.1/mydb" />
    <property name="username" value="root" />
    <property name="password" value="password" />
</bean>
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<!-- <tx:annotation-driven /> -->
<bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="persistenceExceptionTranslationPostProcessor"

class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

<bean id="userDaoImpl" class="dao.UserDaoImpl" />
<bean id="userServiceImpl" class="services.UserServiceImpl" />

web.xml

<web-app>
<display-name>Archetype Created Web Application</display-name>

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-servlet.xml</param-value>
</context-param>
<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

UserController Class

   package controller;
   @RestController
    public class UserController {
 @Autowired
 IUserService userService;
    @RequestMapping(value = "/user/", method = RequestMethod.GET)
    public ResponseEntity<List<User>> listAllUsers() {
         System.out.println("fadfa");
        List<User> users = userService.findUsers();
        System.out.println("fadfa");
        if(users.isEmpty()){
            return new ResponseEntity<List<User>>(HttpStatus.NO_CONTENT);//You many decide to return HttpStatus.NOT_FOUND
        }
        return new ResponseEntity<List<User>>(users, HttpStatus.OK);
    }

I tried it : http://localhost:8080/MoviesStore/user/ but get: HTTP Status 404!!!

Can anyone tell me what I missed or I did wrong?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
dany
  • 11
  • 5
  • What makes you think you shouldn't be getting 404? What part of your configuration sets up Spring MVC to use your `UserController` handler to serve the request? Why do you think so? – Sotirios Delimanolis Nov 12 '15 at 22:29
  • i put this in spring-servlet.xml and I think you should access the class UserController...or not? – dany Nov 12 '15 at 22:32
  • So what? What does that do? Why would it make your application work (which obviously it doesn't)? – Sotirios Delimanolis Nov 12 '15 at 22:34
  • What's more, for some reason, you're making both your `DispatcherServlet` and `ContextLoaderListener` load their respective contexts from the same source. You're loading the same application context twice. – Sotirios Delimanolis Nov 12 '15 at 22:36
  • for http://localhost:8080/MoviesStore/index.jsp it is ok...but I do not understand why not works http://localhost:8080/MoviesStore/user/ – dany Nov 12 '15 at 22:38
  • Do you understand why `localhost:8080/MoviesStore/index.jsp` works? I think you should be reading the Spring MVC documentation. – Sotirios Delimanolis Nov 12 '15 at 22:39
  • i tried a tutorial for this, but the same result.... – dany Nov 12 '15 at 23:04

0 Answers0