WebSphere7-404在url中不包含尾部斜杠时

WebSphere7-404在url中不包含尾部斜杠时,websphere,websphere-7,Websphere,Websphere 7,我正在从事一个使用Spring4MVC、AngularJS和WebSphere7的项目。当我将应用程序构建为war并通过WebSphere7管理控制台安装它时,一切正常。但是,我需要将war包装在EAR中(而不是websphere自动包装它的通用EAR)。因此,我创建了一个单独的项目,它接受战争并将其包装在耳朵中 当我转到urlhttp://localhost:9080/public/myapp然后我得到一个404,它找不到资源。当我像这样在它上面添加一个尾随斜杠时http://localhos

我正在从事一个使用Spring4MVC、AngularJS和WebSphere7的项目。当我将应用程序构建为war并通过WebSphere7管理控制台安装它时,一切正常。但是,我需要将war包装在EAR中(而不是websphere自动包装它的通用EAR)。因此,我创建了一个单独的项目,它接受战争并将其包装在耳朵中

当我转到url
http://localhost:9080/public/myapp
然后我得到一个404,它找不到资源。当我像这样在它上面添加一个尾随斜杠时
http://localhost:9080/public/myapp/
然后它重定向到
index.html
资源。我需要它来找到
index.html
,当我转到没有尾部斜杠的url时。我怎样才能让它工作呢

以下是我的配置文件:

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

我的耳朵
myapp-web-2.0-SNAPSHOT.war
/公共/我的应用程序
战争中的ibm-web-bnd.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>
<?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>
<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>
<?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>

战争中的web.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>
<?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>
<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>
<?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>

myapp
org.springframework.web.servlet.DispatcherServlet
1.
myapp
/
myapp服务
UwProfileDataSource
javax.sql.DataSource
容器
可分享
战争中的myapp-servlet.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>
<?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>
<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>
<?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>

UwProfileDataSource
真的

您是在部署期间手动映射URL,还是在application.xml中定义了URL?@AlastairMcCormack我在EAR文件中定义了URL,我将继续从WAR的webinf文件夹以及EAR中的application.xml中发布我的ibm-web-bnd.xml。当您通过IHS访问它时,它能工作吗?@AlastairMcCormack我对IHS没有任何经验。但应用程序本身运行良好,我只需要去掉尾随的斜杠。这是一项要求,因为我们门户中的许多其他应用程序都指向该URL位置;IHS/Apache通常会处理这个问题