圆形视图路径,Spring Boot,Gradle和mvc

时间:2014-12-30 19:46:25

标签: spring spring-mvc gradle

我正在尝试使用spring boot执行应用程序但是我收到以下错误消息:“循环视图路径[index]:将再次调度回当前处理程序URL [/ test / index]”。我已经看到一些类似的帖子,但我没有成功。

您可以在下面看到错误消息:

Circular view path [index]: would dispatch back to the current handler URL [/test/index] again

的build.gradle

buildscript {
repositories { 
    mavenCentral()
    maven { url "http://repo.spring.io/snapshot" }

}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.1.BUILD-SNAPSHOT")
}

}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'spring-boot'
apply plugin: 'war'

repositories {
    maven { url "http://repo.spring.io/snapshot" }
    maven { url "http://repo.spring.io/milestone" }
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile 'org.springframework:spring-webmvc:3.2.2.RELEASE'
    compile 'jstl:jstl:1.2'
    providedRuntime 'org.apache.tomcat.embed:tomcat-embed-jasper'
}

WebMvcConfig.java

package com.hellomvc.test.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@EnableWebMvc
@Configuration
class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
    configurer.enable();
}

@Bean
public InternalResourceViewResolver viewResolver() {
    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setPrefix("WEB-INF/pages/");
    resolver.setSuffix(".jsp");
    resolver.setCache(false);
    resolver.setOrder(2);
    return resolver;
}

}

AppInitializer

package com.hellomvc.test.initializer;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

public class AppInitializer implements WebApplicationInitializer {
private static final String CONFIG_LOCATION = "com.hellomvc.test.config";
private static final String MAPPING_URL = "/";

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    WebApplicationContext context = getContext();
    servletContext.addListener(new ContextLoaderListener(context));
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new   DispatcherServlet(context));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping(MAPPING_URL);
}

private AnnotationConfigWebApplicationContext getContext() {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setConfigLocation(CONFIG_LOCATION);
    return context;
}

}

控制器

package com.hellomvc.test.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@Configuration
@ComponentScan("com.hello.spring.example.controller")
@EnableAutoConfiguration
public class HelloController {
@RequestMapping(value = "/test/{name}", method = RequestMethod.GET)
public ModelAndView welcome(@PathVariable("name") String name) {

    ModelAndView model = new ModelAndView();
    model.setViewName("index");
    model.addObject("name", name);

    return model;

}

public static void main(String[] args) {enter code here
    SpringApplication.run(HelloController.class, args);
}

}

感谢您的帮助。 埃德加多

0 个答案:

没有答案