spring-guides / gs-batch-processing

Creating a Batch Service :: Learn how to create a basic batch-driven solution.

Home Page:https://spring.io/guides/gs/batch-processing/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to integrate spring batch admin into this demo?

fabn opened this issue · comments

I'm evaluating spring boot for a batch project and I'd like to integrate also batch admin ui. I used this project as proof of concept to develop basic functionalities but I'm not able to integrate the admin ui. Is it possible? Any hint on how to do that?

I never tried it. Spring Batch Admin is designed to be embeddable and to use resources on the classpath, so it should be possible. It also uses freemarker, so you'll need to disable the template checks done by Spring Boot (unless you are using your own templates): "spring.freemarker.checkTemplateLocation=false".

I tried lot of different combinations to get it working, but it seems impossible...

I write here some attempt I did just for reference, but I think that I won't be able to solve those issues

In one of the latest attempt I created a config class which should replace batch admin web.xml file

@Configuration
@ImportResource({
        "classpath*:/org/springframework/batch/admin/web/resources/webapp-config.xml",
        "classpath*:/org/springframework/batch/admin/web/resources/servlet-config.xml"
})
public class BatchAdminConfiguration {


    @Bean
    public FilterRegistrationBean shallowEtagHeaderFilter() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(new ShallowEtagHeaderFilter());
        registrationBean.setOrder(1);
        registrationBean.addUrlPatterns("/*");
        return registrationBean;
    }

    @Bean
    public FilterRegistrationBean hiddenHttpMethodFilter() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(new HiddenHttpMethodFilter());
        registrationBean.setOrder(2);
        registrationBean.addUrlPatterns("/*");
        return registrationBean;
    }
}

But the servlet-config context throw this exception when validating xml file.

Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 20 in XML document from URL [jar:file:/Users/fabio/.m2/repository/org/springframework/batch/spring-batch-admin-manager/1.3.0.M1/spring-batch-admin-manager-1.3.0.M1.jar!/META-INF/spring/batch/servlet/manager/integration-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 104; cvc-complex-type.3.2.2: l'attributo "name" non è consentito nell'elemento "http:inbound-channel-adapter".
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:242)
    ... 32 more

If I remove it leaving the webapp-config.xml alone I get this other exception

Caused by: java.lang.ClassCastException: org.springframework.batch.core.repository.support.JobRepositoryFactoryBean$$EnhancerBySpringCGLIB$$316bbfdf cannot be cast to org.springframework.batch.core.repository.JobRepository
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$850e79c.jobRepository(<generated>)
    at org.springframework.batch.core.configuration.annotation.AbstractBatchConfiguration.jobBuilders(AbstractBatchConfiguration.java:60)
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$850e79c.CGLIB$jobBuilders$7(<generated>)
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$850e79c$$FastClassBySpringCGLIB$$35744317.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$850e79c.jobBuilders(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
    ... 24 more

I think that the main incompatibility is spring version, they seems to target older spring versions. Maybe I'll file an issue in BATCHADM Jira and ask them for help.

Thanks.

I think it would be best to entertain creating a separate guide focused on that.

I opened spring-guides/getting-started-guides#4 to track such effort