Spring Batch Admin + Spring Boot - 模糊映射。无法映射' org.springframework.batch.admin.web.JobController#1'方法

时间:2017-03-03 08:01:53

标签: spring-mvc spring-boot spring-batch spring-batch-admin

我正在尝试使用spring-batch-admin-samples project.

获得Spring Batch Admin UI

我的工作使用Spring Boot,我已经将我的主应用程序类更改为可以使用this link部署到Weblogic。

所以应用程序类看起来像,

@SpringBootApplication(exclude = { HypermediaAutoConfiguration.class,
        MultipartAutoConfiguration.class })
@EnableBatchAdmin
public class MyApplication extends SpringBootServletInitializer
        implements WebApplicationInitializer {

    @Override
    protected SpringApplicationBuilder configure(
            SpringApplicationBuilder builder) {
        return configureApplication(builder);
    }

    public static void main(String[] args) {
        configureApplication(new SpringApplicationBuilder()).run(args);
    }

    private static SpringApplicationBuilder configureApplication(
            SpringApplicationBuilder builder) {
        return builder.sources(MyApplication.class).bannerMode(Banner.Mode.OFF);
    }
}

我也从配置类中删除了 - @EnableBatchProcessing

到目前为止,我收到了很多错误(超过10个)并且能够通过覆盖xmls等或通过添加属性来超越每个错误。

以下错误是我无法解决的问题,

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'org.springframework.batch.admin.web.JobController#1' method 
public java.lang.String org.springframework.batch.admin.web.JobController.launch(org.springframework.ui.ModelMap,java.lang.String,org.springframework.batch.admin.web.LaunchRequest,org.springframework.validation.Errors,java.lang.String)
to {[/jobs/{jobName}],methods=[POST]}: There is already 'org.springframework.batch.admin.web.JobController#0' bean method
public java.lang.String org.springframework.batch.admin.web.JobController.launch(org.springframework.ui.ModelMap,java.lang.String,org.springframework.batch.admin.web.LaunchRequest,org.springframework.validation.Errors,java.lang.String) mapped.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134)
    at com.hms.responsematching.batch.ResponseMatchingApplication.main(ResponseMatchingApplication.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59)
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'org.springframework.batch.admin.web.JobController#1' method 
public java.lang.String org.springframework.batch.admin.web.JobController.launch(org.springframework.ui.ModelMap,java.lang.String,org.springframework.batch.admin.web.LaunchRequest,org.springframework.validation.Errors,java.lang.String)
to {[/jobs/{jobName}],methods=[POST]}: There is already 'org.springframework.batch.admin.web.JobController#0' bean method
public java.lang.String org.springframework.batch.admin.web.JobController.launch(org.springframework.ui.ModelMap,java.lang.String,org.springframework.batch.admin.web.LaunchRequest,org.springframework.validation.Errors,java.lang.String) mapped.
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.assertUniqueMethodMapping(AbstractHandlerMethodMapping.java:576)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:540)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:264)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:250)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:214)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:184)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:128)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    ... 23 common frames omitted

我可以想到两个问题,

1. org.springframework.batch.admin.web.JobController有两种方法具有相同的URL但不同的HTTP方法 - launch& details

<dependency>
        <groupId>org.springframework.batch</groupId>
        <artifactId>spring-batch-admin-manager</artifactId>
        <version>2.0.0.BUILD-SNAPSHOT</version>
</dependency>
  1. spring-batch-admin-resources 项目中的web.xml使用两个xmls中的contextConfigLocation,因此可能存在上下文加载问题。

    <context-param><param-name>contextConfigLocation</param-name> <param-value>classpath*:/org/springframework/batch/admin/web/resources/webapp-config.xml</param-value> </context-param>

  2. <servlet>
            <servlet-name>Batch Servlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>classpath*:/org/springframework/batch/admin/web/resources/servlet-config.xml</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
    

    如果需要更多详细信息,请建议并告知我们。

    编辑:通过查看this question的已接受答案,似乎相同的网址可以应用于不同的HTTP方法,并且不会产生错误。原因是在其他地方。

    我只是不明白,当运行jar spring-batch-admin-samples project.时,一切正常如何,但在尝试自己的类似代码时开始接收问题。应用类与样品中提到的相同。当您尝试通过覆盖下面提到的这两个xml来解决下面关于对象映射器的问题时,您开始收到问题映射问题。

    Constructor in org.springframework.boot.actuate.autoconfigure.EndpointMBeanExportAutoConfiguration required a single bean, but 2 were found:
        - jacksonMapper: defined in URL [jar:file:/D:/RunRC/ResponseMatching/ResponseMatchingWithAdmin-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-batch-admin-resources-2.0.0.BUILD-SNAPSHOT.jar!/META-INF/spring/batch/servlet/resources/resources-context.xml]
        - objectMapper: defined in URL [jar:file:/D:/RunRC/ResponseMatching/ResponseMatchingWithAdmin-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-batch-admin-manager-2.0.0.BUILD-SNAPSHOT.jar!/META-INF/spring/batch/servlet/manager/controller-context-legacy.xml]
    
    
    Action:
    
    Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
    

    完成修复Proxy Issue on SimpleJobService

    后,开始收到上述问题

    覆盖controller-context-legacy.xml没有条目/空文件或单个条目,<bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper" primary="true"/>没有影响。

    总而言之,我只想用我的工作来运行所述示例项目。一个区别是示例项目使用Gradle,而我使用Maven来构建我的项目。我的工作已经使用Maven编写,所以继续这样做。

1 个答案:

答案 0 :(得分:1)

经过几天的点击和试用,我可以让Sample Github项目为我的工作而工作。两个根本原因,

1. @Configuration&amp; @SpringBootApplication在我的工作的同一个包中:我的上下文被初始化了两次,因为我在同一个包中有两个类,所以我不得不将配置类移动到与主类不同的包。

2. Spring Boot版本:示例项目在Spring Boot版本1.2.2.RELEASE中进行编码,而我的工作是使用1.4.0.RELEASE而导致objectMapper问题。项目使用1.2.2.RELEASE以及最新版本1.5.2.RELEASE,因此我将自己升级到1.5.2.RELEASE。

我遇到了其他各种问题,

  • JNDI数据源使用

  • 应用程序上下文路径更改

  • 通过Spring Scheduler启动作业

  • Logback Logging

  • 读取非标准引导属性

我的部署环境是Weblogic,RDBMS是DB2。我能够解决所有这些问题,主要是我的 spring-batch-admin-manager API的重写XML。

enter image description here

希望这有助于任何人将该示例项目作为起点。