【问题标题】:Spring MVC Application runs on "incorrect" URLSpring MVC 应用程序在“不正确”的 URL 上运行
【发布时间】:2012-02-14 14:05:02
【问题描述】:

我正在与其他人一起开发 Spring MVC Web 应用程序。如果我运行应用程序,它使用 URL http://localhost:8080/mywebapp,但如果其他人运行它,应用程序使用 URL http://localhost:8080/x

我可以做任何配置来让应用程序在特定的 URL 上运行吗?

applicationContext.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"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.0.xsd
                        http://www.springframework.org/schema/mvc 
                        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

        <context:annotation-config />

        <context:component-scan base-package="z.y.x.mywebapp" />

        <mvc:annotation-driven /> 

        <import resource="hibernate-context.xml" />

</beans>

web.xml

 <?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
        xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

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

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

        <servlet-mapping>
                <servlet-name>default</servlet-name>
                <url-pattern>*.css</url-pattern>
        </servlet-mapping>

        <servlet-mapping>
                <servlet-name>default</servlet-name>
                <url-pattern>*.png</url-pattern>
        </servlet-mapping>

        <servlet-mapping>
                <servlet-name>default</servlet-name>
                <url-pattern>*.gif</url-pattern>
        </servlet-mapping>

                <servlet-mapping>
                <servlet-name>default</servlet-name>
                <url-pattern>*.js</url-pattern>
        </servlet-mapping>

        <listener>
                <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
</web-app>

spring-servlet.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:p="http://www.springframework.org/schema/p"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

        <bean
                class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <property name="prefix" value="/WEB-INF/views/" />
                <property name="suffix" value=".jsp" />
        </bean>
</beans>

我对此很陌生,如果有任何信息丢失,请告诉我。

谢谢

【问题讨论】:

    标签: java spring-mvc


    【解决方案1】:

    它在 tomcat 中的 server.xml 中定义:

    <Context docBase="yourSource" path="/yourPath" ...
    

    如果使用war文件,war文件本身的名称(您可以右键单击重命名),如果使用maven,则在pom中设置:

    &lt;build&gt;&lt;finalname&gt;blahblah

    【讨论】:

    • 我想问题是,我们没有在任何地方定义它。在 server.xml 和 pom 中都没有。谢谢,我会试试的。
    猜你喜欢
    • 2023-03-16
    • 1970-01-01
    • 2017-03-02
    • 2013-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-04
    • 2018-03-13
    相关资源
    最近更新 更多