Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将web.xml的某些部分更改为java配置_Java_Tomcat_Jboss_Web.xml - Fatal编程技术网

如何将web.xml的某些部分更改为java配置

如何将web.xml的某些部分更改为java配置,java,tomcat,jboss,web.xml,Java,Tomcat,Jboss,Web.xml,我尝试用java配置替换web.xml(我使用Spring,但没有Spring引导)。我移动了web.xml的某些部分,如添加过滤器、servlet和侦听器,如下面的代码所示: public class ServletInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletExcep

我尝试用java配置替换web.xml(我使用Spring,但没有Spring引导)。我移动了web.xml的某些部分,如添加过滤器、servlet和侦听器,如下面的代码所示:

public class ServletInitializer implements WebApplicationInitializer {
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
      AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
      context.register(MyApplication.class);
      servletContext.addListener(new ContextLoaderListener(context));

      addFilters(servletContext);
      addServlets(servletContext, context);
    }

    private void addServlets(ServletContext servletContext, AnnotationConfigWebApplicationContext context) {
      ServletRegistration.Dynamic dispatcher = servletContext
            .addServlet("DispatcherServlet", new DispatcherServlet(context));
      dispatcher.setLoadOnStartup(1);
      dispatcher.addMapping("/");

      ServletRegistration.Dynamic mvcServlet = servletContext
            .addServlet("MvcServlet", new DispatcherServlet(context));
      mvcServlet.setLoadOnStartup(1);
      mvcServlet.addMapping("/mvc/*");
    }

    private void addFilters(ServletContext servletContext) {
      servletContext.addFilter("characterEncoding", new CharacterEncodingFilter("UTF-8", true))
            .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");

      servletContext.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class)
            .addMappingForUrlPatterns(null, false, "/*");

      servletContext.addFilter("i18nOutputFilter", DelegatingFilterProxy.class)
            .addMappingForUrlPatterns(
                  EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");
    }
}
不幸的是,我不知道如何处理这些元素:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Unsecured website</web-resource-name>
        <url-pattern>/mvc/extNavigation/*</url-pattern>
        <http-method>GET</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>authenticated</role-name>
    </auth-constraint>
</security-constraint>

<security-role>
    <description>Access to use the Secured web site - authenticated</description>
    <role-name>authenticated</role-name>
</security-role>

<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/loginSSO.jsp</form-login-page>
        <form-error-page>/errorSSO.jsp</form-error-page>
    </form-login-config>
</login-config>

无担保网站
/mvc/extNavigation/*
得到
认证
使用安全网站的访问权限-已验证
认证
形式
/loginSSO.jsp
/errorSSO.jsp
你知道解决办法吗