首页 文章

Spring Batch Admin - 如何隐藏标准菜单,如主页和文件菜单

提问于
浏览
2

有没有办法覆盖spring-batch-admin-manager中的/META-INF/spring/batch/servlet/manager/manager-context.xml?我想删除主页和文件菜单(这是标准菜单) . 请在下面找到导航菜单栏的屏幕截图 .

Spring Batch Admin with standard menus

我试图在我的webapp的src / main / resources / META-INF / spring / batch / override文件夹下创建manager-context.xml的副本,并注释掉以下代码行 .

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

但是,它会创建重复的菜单,因为spring-batch-admin-manager.jar中的原始manager-context.xml首先被加载,然后我的应用程序特定的manager-context.xml被加载 .

我还尝试通过仅从我的webapp加载manager-context.xml来改变webapp上下文的初始化方式 . 这是我的webapp-context.xml . 我在这里添加了注释来解释我是如何尝试仅从我的webapp加载manager-context.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"
    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>

不幸的是,应用程序无法加载连接到“作业和执行”菜单的任何自由标记模板(* .ftl文件),因此我无法使用任何菜单 . 我正在谈论的ftl文件位于spring-batch-admin-manager源代码中的src / main / resources / org / springframework / batch / admin / web / manager文件夹下 .

2 回答

  • 0

    我有同样的问题 . 为了解决这个问题,我创建了src / main / resources / org / springframework / batch / admin / web / layouts / html / navigation.ftl文件,其中包含以下内容:

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

    其中<#if menu_index!= 0 && menu_index!= 3>我跳过"Home"菜单(索引= 0)和"File"菜单(索引= 3)

  • 3

    您必须覆盖要修改的bean:例如,如果您想要标准菜单,则必须覆盖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>
    

    然后你可以创建另一个没有菜单或不同CSS文件的ftl文件 .

相关问题