需要springmvc-router配置协助

时间:2015-06-02 07:04:57

标签: java spring spring-mvc

我按照本教程http://resthub.github.io/springmvc-router/使用routes.conf文件实现弹簧路由。使用下面的代码

// Configuration code as mentioned in tutorial
import java.util.ArrayList;
import java.util.List;

import org.resthub.web.springmvc.router.RouterConfigurationSupport;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan(basePackages = "my base pack")
// You should not use the @EnableWebMvc annotation
public class WebAppConfig extends RouterConfigurationSupport {

    @Override
    public List<String> listRouteFiles() {

        List<String> routeFiles = new ArrayList<String>();

        routeFiles.add("routes.conf");

        return routeFiles;
    }
}

routes.conf位于src\main\resources

springmvc-router没有选择routes.conf文件

我遇到以下异常:

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'handlerMapping' defined in ServletContext   
resource [/WEB-INF/axpense-servlet.xml]: Initialization of bean failed;

nested exception is org.resthub.web.springmvc.router.exceptions.RouteFileParsingException:
Could not read route configuration files; 

nested exception is java.io.FileNotFoundException: 
Could not open ServletContext resource [/routes.conf] at 
org.springframework.beans.factory.support.AbstractAutowireCapableBean

1 个答案:

答案 0 :(得分:0)

简单地替换line routeFiles.add(“routes.conf”); with routeFile.add(classpath:/routes.conf); //为我工作