繁体   English   中英

Spring-boot:应用程序无法启动

[英]Spring-boot : Application could not start

Dear All,

I m new to Spring-Boot. I have created this service restful service, which generates the following error. I understand that NativeWebRequest is an Interface and needs to be implemented by a bean that will implement this interface, but I don't know if this is the right approach? 
Unfortunately, I spend already many days trying to understand what could be the origin of the problem. Any help/advice will really be appreciated.

Thank you for your attention.

Evangelos
The Application

...

package server;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import server.service.controllers.CSVReadAndParseToBean;


@SpringBootApplication
@Configuration
public class Application {

    public static void InitializeReferenceData() throws Exception {

        CSVReadAndParseToBean csv2bean= new CSVReadAndParseToBean();
        csv2bean.InitializeRefEicCode();

    }

    public static void main(String[] args) throws Exception {
        InitializeReferenceData();
        SpringApplication.run(Application.class, args);
    }
}

...

2) The Interface

...

@Validated
@Api(value = "execute_rules", description = "Execute the rule validation on the received message")
public interface ExecuteRulesApi {

    default Optional<NativeWebRequest> getRequest() {
        return Optional.empty();
    }

    @ApiOperation(value = "", nickname = "executeRulesPost", notes = "", response = ResultMsg.class, tags={  })
    @ApiResponses(value = { 
        @ApiResponse(code = 201, message = "Return an object with the validation status ", response = ResultMsg.class) })
    @RequestMapping(value = "/execute_rules",
        produces = { "application/json" }, 
        consumes = { "application/json" },
        method = RequestMethod.POST)
    default ResponseEntity<ResultMsg> executeRulesPost(@ApiParam(value = "" ,required=true )  @Valid @RequestBody RequestMsg requestMsg) throws JsonProcessingException {
        System.out.println (" **** Call to - ExecuteRulesApiInterface");
         String result = ApiUtil.processMessageBody(requestMsg);
        getRequest().ifPresent(request -> {
            for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
                if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
                    ApiUtil.setMsgResponse(request, "application/json", result);
                    break;
                }
            }
            System.out.println (" **** Call to Exit ExecuteRulesApiInterface");
        });    ***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in server.service.api.ExecuteRulesApiController required a bean of type 'org.springframework.web.context.request.NativeWebRequest'
 that could not be found.


Action:

Consider defining a bean of type 'org.springframework.web.context.request.NativeWebRequest' in your configuration.


Process finished with exit code 1    ***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in server.service.api.ExecuteRulesApiController required a bean of type 'org.springframework.web.context.request.NativeWebRequest'
 that could not be found.


Action:

Consider defining a bean of type 'org.springframework.web.context.request.NativeWebRequest' in your configuration.


Process finished with exit code 1

        return new ResponseEntity<>(HttpStatus.CREATED);

    }

...

3) The Code Implementation

...

@Controller
@RequestMapping("${openapi.demoNewTPRulesEngine.base-path:/api-rules}")

public class ExecuteRulesApiController implements ExecuteRulesApi {

    private @Autowired
    final NativeWebRequest request;

    @org.springframework.beans.factory.annotation.Autowired
    public ExecuteRulesApiController(NativeWebRequest request) {
        this.request = request;
        System.out.println (" **** Call to Constructor of ExecuteRulesApiController *****");

    }

    @Override

    public Optional<NativeWebRequest> getRequest( ) {

        System.out.println (" **** Call to Override getRequest methodes.*****");
        System.out.println (" **** Received Payload is:" +this.request.toString());

        return Optional.ofNullable(request);
    }

}

...

The Service definition.

...

4) 豆子.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
        <bean class="org.springframework.web.context.request.NativeWebRequest" abstract="true"/>
        <bean/>

</beans>

...

5) Final Error

...

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in server.service.api.ExecuteRulesApiController required a bean of type 'org.springframework.web.context.request.NativeWebRequest'
 that could not be found.


Action:

Consider defining a bean of type 'org.springframework.web.context.request.NativeWebRequest' in your configuration.


Process finished with exit code 1

...

我认为错误是这个:

<bean class="org.springframework.web.context.request.NativeWebRequest" abstract="true"/>

如果将其声明为抽象,则 Spring 不会创建实例,spring 配置中的“抽象”bean 用于设置为其他 bean 的父类。

NativeWebRequest 是一个接口,你可以创建一个接口的 bean,尝试其中一个实现。 也许是 ServletWebRequest?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM