如何为Angular应用程序配置Weblogic应用程序服务器

时间:2018-10-31 17:17:55

标签: angular weblogic config

我有一个Angular(6.1)应用程序,该应用程序打包在WAR(和EAR)文件中,应该部署到Weblogic(12c)。
基于this链接,应将对应用程序的所有请求(上下文根)都路由到index.html应用程序文件。

文档中有一些配置示例,但没有针对WebLogic之类的应用服务器的配置示例。 由于它应该与应用程序耦合,因此它将进入WAR,我想到了在web.xml中使用servlet映射。我玩过它,但是没有用。 (内部服务器错误,未找到默认视图以外的视图...即使我在雄猫中使用普通的WAR,WebLogic拒绝这样做,...)

在投入大量时间之前-这是正确的方法吗?
如果是这样,正确的映射/图案会是什么样?
如果没有,在WAR中进行配置的另一种方法是什么?

3 个答案:

答案 0 :(得分:1)

如果比创建自己的过滤器更舒适,则可以使用:org.tuckey.urlrewritefilter http://tuckey.org/urlrewrite/

简单的3个步骤:

  1. 将依赖项添加到pom.xml
  2. 将来自tuckey的过滤器UrlRewriteFilter添加到web.xml
  3. 在 urlrewrite.xml

根据我的经验,它非常方便(尤其是与web.xml中支持的模式相比)。
规则示例可能是:

<rule>
    <from>^/webapp/*</from>
    <to>/webapp/index.html</to>
</rule>

答案 1 :(得分:0)

使用Servlet过滤器。如果请求是GET,并且应该转发到index.html,则将其转发到index.html。否则,将请求向下传递。这是此类过滤器的示例。当然,根据您的应用程序的体系结构,条件可能有所不同:

@WebFilter(value = "/*")
public class IndexFilter implements Filter {
    @Override
    public void doFilter(ServletRequest req,
                         ServletResponse response,
                         FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        if (mustForward(request)) {
            request.getRequestDispatcher("/index.html").forward(request, response);
            return;
        }

        chain.doFilter(request, response);
    }

    private boolean mustForward(HttpServletRequest request) {
        if (!request.getMethod().equals("GET")) {
            return false;
        }

        String uri = request.getRequestURI();

        return !(uri.startsWith("/api")
            || uri.endsWith(".js")
            || uri.endsWith(".css")
            || uri.startsWith("/index.html")
            || uri.endsWith(".ico")
            || uri.endsWith(".png")
            || uri.endsWith(".jpg")
            || uri.endsWith(".gif")
            || uri.endsWith(".eot")
            || uri.endsWith(".svg")
            || uri.endsWith(".woff2")
            || uri.endsWith(".ttf")
            || uri.endsWith(".woff");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        // nothing to do
    }

    @Override
    public void destroy() {
        // nothing to do
    }
}

答案 2 :(得分:0)

将以下代码添加到web.xml中,而不在您的URL中添加index.html,http://yourwebsite/将成功加载您的网站。 由于某些原因,将此项添加到现有的欢迎文件列表中不起作用。我是Java新手,所以我不确定为什么。如下所示,使用index.html添加了一个欢迎文件列表的新部分,从而解决了该问题。

 <welcome-file-list>
   <welcome-file>index.html</welcome-file>
 </welcome-file-list>