Websphere 7 - 404不包括url中的尾部斜杠

时间:2016-03-10 17:31:09

标签: websphere websphere-7

我正在使用Spring 4 MVC,AngularJS和Websphere 7开发一个项目。当我将我的应用程序构建为战争并通过Websphere 7管理控制台安装它时,一切正常。但是,我需要在EAR中包含我的战争(不是websphere自动包装它的通用EAR)。所以我创建了一个单独的项目,它接受WAR并将其包装在EAR中。

当我转到网址http://localhost:9080/public/myapp时,我得到一个404,它无法找到资源。当我像这样http://localhost:9080/public/myapp/一样在其上添加一个尾部斜杠时,它就会重定向到index.html资源。当我转到没有尾随斜线的网址时,我需要它来找到index.html。我怎样才能让它发挥作用?

这是我的配置文件:

EAR中的application.xml

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
  <display-name>myapp-ear</display-name>
  <module>
    <web>
      <web-uri>myapp-web-2.0-SNAPSHOT.war</web-uri>
      <context-root>/public/myapp</context-root>
    </web>
  </module>
</application>
WAR中的

ibm-web-bnd.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
         version="1.0">

    <virtual-host name="default_host"/>

    <resource-ref name="UwProfileDataSource" binding-name="jdbc/uwprofile"></resource-ref>
</web-bnd>

WAR中的web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

    <servlet>
        <servlet-name>myapp</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>myapp</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <resource-ref>
        <description>myapp Service</description>
        <res-ref-name>UwProfileDataSource</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>

</web-app>
WAR中的

myapp-servlet.xml

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

    <context:component-scan base-package="com.myapp"/>
    <mvc:annotation-driven/>
    <mvc:default-servlet-handler/>
    <mvc:resources mapping="/**" location="classpath:/app/"/>
    <mvc:view-controller path="/" view-name="forward:/index.html" />


    <bean id="uwProfileDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName"><value>UwProfileDataSource</value></property>
        <property name="resourceRef"><value>true</value></property>
    </bean>

</beans>

0 个答案:

没有答案