RepositoryRestController 不工作

RepositoryRestController is not working

我的英语不是很好请理解。

这可能没有帮助,但我会让你知道我的地址。 git

RepositoryRestController 不工作。
@BasePathAwareController, @RepositoryRestController 两者都不行。
如果在class区使用映射,则不能使用其他repo。
它在一天前使用相同的来源。

开发环境
java1.8
spring4.3.8
spring 数据 mongo 1.10.3
spring数据休息2.6.10
spring 讨厌的 0.23.0
mongo 驱动程序 3.0.2

控制器

@RepositoryRestController
//@BasePathAwareController
//@RequestMapping(value = "")
public class ArticleController {

@Resource(name="articleCustomRepo")
private ArticleCustomRepository cRepo;

@Resource(name="articleService")
private ArticleService 

    @RequestMapping(value="/articles/{idx}/comments",method=RequestMethod.GET,produces="application/hal+json")
    public @ResponseBody HttpEntity<List<CommentResource>> getComment(@PathVariable("idx") int idx) {

        List<CommentResource> list = cRepo.data(idx);

        return new ResponseEntity<>(list,HttpStatus.OK);
    }

    @RequestMapping(value="/articles",method=RequestMethod.POST,produces="application/hal+json")
    public HttpEntity<ArticleResource> postArticle(@RequestBody Map<String,Object> map) {

            ArticleResource article = service.postArticle(map);

            return new ResponseEntity<>(article, HttpStatus.OK);
        }
    }

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value><!--  -->classpath*:config/spring/context-config.xml</param-value>
        </context-param>


    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <servlet>
            <servlet-name>rest</servlet-name>
            <servlet-class>org.springframework.data.rest.webmvc.RepositoryRestDispatcherServlet</servlet-class>
        <init-param>
            <param-name>throwExceptionIfNoHandlerFound</param-name>
            <param-value>false</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>rest</servlet-name>
        <url-pattern>/api/v1/*</url-pattern>
    </servlet-mapping>

</web-app>

上下文-config.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:component-scan base-package="horizon">
    </context:component-scan>

</beans>

SpringConfig.java

package horizon.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
import org.springframework.hateoas.config.EnableEntityLinks;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@Configuration
@EnableWebMvc
@EnableEntityLinks
@EnableSpringDataWebSupport
public class SpringConfig {

}

帮我想办法解决这个问题。

  • 您似乎在 slf4j 和 log4j 之间有一个调用循环尝试从您那里删除 log4j 依赖项pom.xml并检查您的 tomcat 日志

  • 创建自定义调度程序 servlet

    public class RestDispatcherServlet extends DispatcherServlet {
     public RestDispatcherServlet() {
      configure();
      }
    
    public RestDispatcherServlet(WebApplicationContext 
        webApplicationContext) {
      super(webApplicationContext);
      configure();
    }
    private void configure() {
    setContextClass(AnnotationConfigWebApplicationContext.class);
    setContextConfigLocation(
    RestMvcConfiguration.class.getName());
     }
    

    }

  • 更新您的 web.xml 调度程序 servlet

  • 创建 rest mvc 应用程序配置

      @ComponentScan("horizon.board.controller")
      public class RestMvcConfiguration extends 
        RepositoryRestMvcConfiguration {
       }