Http状态404-其余控制器未映射到corectly?

时间:2015-11-12 22:27:32

标签: java spring hibernate spring-mvc spring-restcontroller

弹簧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”/&gt;

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

   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);
    }

我试过了:http://localhost:8080/MoviesStore/user/但得到:HTTP状态404 !!!

任何人都可以告诉我我错过了什么或 我做错了?

0 个答案:

没有答案