Anand
Anand

Reputation: 1841

Spring Batch Admin - How to hide standard menus such as home and files menu

Is there a way to override the /META-INF/spring/batch/servlet/manager/manager-context.xml in spring-batch-admin-manager? I would like to remove the home and files menu (which are standard menus). Please find attached the screenshot of the navigation menu bar below.

Spring Batch Admin with standard menus

I tried to create a duplicate of the manager-context.xml under src/main/resources/META-INF/spring/batch/override folder of my webapp and comment out the following lines of code.

<bean class="org.springframework.batch.admin.web.HomeMenu" parent="baseMenu"/>
<bean class="org.springframework.batch.admin.web.FilesMenu" parent="baseMenu"/>

But, it creates duplicate menus as the original manager-context.xml in the spring-batch-admin-manager.jar gets loaded first and my application specific manager-context.xml gets loaded later.

I also tried changing the way webapp context is initialized by loading the manager-context.xml only from my webapp. Here is my webapp-context.xml. I have added comments here to explain how I am trying to load the manager-context.xml only from my webapp.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<import resource="classpath*:/META-INF/spring/batch/servlet/resources/*.xml" />
<import resource="classpath*:/META-INF/spring/batch/bootstrap/**/*.xml" />
<import resource="classpath*:/META-INF/spring/batch/override/**/*.xml" />
<!-- Instead of loading manager-context from spring-batch-admin-manager.jar,
the following line is commented out -->
<!-- <import resource="classpath*:/META-INF/spring/batch/servlet/manager/*.xml" /> -->
<!-- Load the manager-context.xml from my web application -->
<import resource="classpath*:/servlet/manager/manager-context.xml" /> 
<import resource="classpath*:/META-INF/spring/batch/servlet/manager/contoller-context.xml" />
<import resource="classpath*:/META-INF/spring/batch/servlet/manager/integration-context.xml" />
<import resource="classpath*:/META-INF/spring/batch/servlet/override/*.xml" />

<!-- Override the standard location for spring batch admin resources -->
<bean id="resourceService"   class="org.springframework.batch.admin.web.resources.DefaultResourceService">
    <property name="servletPath" value="/admin-console" />
</bean>

<bean id="parameterUnpackerFilter"  class="org.springframework.batch.admin.web.filter.ParameterUnpackerFilter">
    <property name="prefix" value="unpack_"/>
    <property name="putEmptyParamsInPath" value="true"/>
</bean>

</beans>

Unfortunately, the application is not able to load any of the free-marker templates (*.ftl files) connected to the Jobs and Executions menu and hence I am not able to use any of menus. The ftl files which I am talking about are located under src/main/resources/org/springframework/batch/admin/web/manager folder in spring-batch-admin-manager source code.

Upvotes: 2

Views: 1615

Answers (2)

Dzmitry Sakovich
Dzmitry Sakovich

Reputation: 31

I had same problem. For solving it I created src/main/resources/org/springframework/batch/admin/web/layouts/html/navigation.ftl file with following contents:

<#assign home_url><@spring.url relativeUrl="${servletPath}/"/></#assign>
<#assign company_url><@spring.messageText code="company.url" text=companyUrl!"http://www.spring.io"/></#assign>
<#assign company_name><@spring.messageText code="company.name" text=companyName!"Spring"/></#assign>
<#assign product_url><@spring.messageText code="product.url" text=productUrl!"http://projects.spring.io/spring-batch/"/></#assign>
<#assign product_name><@spring.messageText code="product.name" text=productName!"Spring Batch"/></#assign>
<div id="primary-navigation">
    <div id="primary-left">
        <ul>
           <#list menuManager.menus as menu>
             <#if menu_index != 0 && menu_index != 3>
                <#assign menu_url><@spring.url relativeUrl="${menu.url}"/></#assign>
                <li><a href="${menu_url}">${menu.label}</a></li>    
             </#if>
           </#list>
        </ul>
    </div>
    <div id="primary-right">
        <ul>
           <li><a href="${company_url}">${company_name}</a></li>
           <li><a href="${product_url}">${product_name}</a></li>
        </ul>
    </div>
</div><!-- /primary-navigation -->

Where <#if menu_index != 0 && menu_index != 3> I skipped "Home" menu (index = 0) and "File" menu (index = 3)

Upvotes: 3

Pablo Lozano
Pablo Lozano

Reputation: 10342

You have to override the beans that you want to modify: for example, if you want to standard menus, you'll have to override the bean standard:

<bean id="standard" parent="parentLayout">
<!--Modify this path to point to another .ftl file -->
    <property name="url" value="/html/MYFILE.ftl" />
    <property name="contentType" value="text/html;charset=UTF-8" />
    <property name="attributes">
        <props merge="true">
            <prop key="body">/layouts/html/home.ftl</prop>
            <!-- Matches the prefix of the servlet mapping in web.xml -->
            <prop key="servletPath">#{resourceService.servletPath}</prop>
        </props>
    </property>
</bean>

And then you can create another ftl file without menus or with different CSS files.

Upvotes: 0

Related Questions