Java Spring启动:应用程序无法启动

Java Spring启动:应用程序无法启动,java,spring-boot,Java,Spring Boot,…我认为错误在于: *************************** APPLICATION FAILED TO START *************************** Description: Parameter 0 of constructor in server.service.api.ExecuteRulesApiController required a bean of type 'org.springframework.web.context.request.N


…我认为错误在于:

***************************
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

如果将其声明为抽象,那么Spring不会创建实例,Spring配置中的“抽象”bean将被设置为其他bean的父类

NativeWebRequest是一个接口,您可以创建一个接口的bean,尝试它们的一种实现。也许是ServletWebRequest

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.
<?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"/>