相关疑难解决方法(0)

Spring Boot删除Whitelabel错误页面

我正在尝试删除白标错误页面,所以我所做的是为"/ error"创建了一个控制器映射,

@RestController
public class IndexController {

    @RequestMapping(value = "/error")
    public String error() {
        return "Error handling";
    }

}
Run Code Online (Sandbox Code Playgroud)

但现在我收到了这个错误.

Exception in thread "AWT-EventQueue-0" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource   [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Invocation  of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'basicErrorController' bean method 
public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>>  org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletR equest)
to {[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'indexController' bean method
Run Code Online (Sandbox Code Playgroud)

不知道我做错了什么.请指教.

编辑:

已经添加 error.whitelabel.enabled=false 到application.properties文件中,仍然会收到相同的错误

spring spring-boot

146
推荐指数
9
解决办法
24万
查看次数

圆形视图路径错误Spring启动

我对Spring很新.我正在尝试使用Spring Boot构建一个MVC应用程序,它显示了一个产品列表.但我收到以下错误:

javax.servlet.ServletException:循环视图路径[products]:将再次调度回当前处理程序URL [/ products].检查您的ViewResolver设置!(提示:由于默认的视图名称生成,这可能是未指定视图的结果.)

这是控制器:

package com.springframeworkguru.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.springframeworkguru.services.ProductService;


    @Controller
    public class ProductController {

        private ProductService productService;

        @Autowired
        public void setProductService(ProductService productService) {
            this.productService = productService;
        }

        @RequestMapping("/products")
        public String listProducts(Model model){

            model.addAttribute("products", productService.listAllProducts());

            return "products";
        }

    }
Run Code Online (Sandbox Code Playgroud)

这是主要类:

package com.springframeworkguru;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

import com.springframeworkguru.controllers.ProductController;

@SpringBootApplication
public class SpringmvcApplication extends SpringBootServletInitializer{

     public static void main(String[] args) {
        SpringApplication.run(SpringmvcApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

并且products.html:

<!DOCTYPE …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-boot

33
推荐指数
5
解决办法
7万
查看次数

标签 统计

spring ×2

spring-boot ×2

java ×1

spring-mvc ×1