java - Spring MVC 应用程序在 "incorrect"URL 上运行

标签 java spring-mvc

我正在与其他人一起开发 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>

我对此还很陌生,如果缺少任何信息,请告诉我。

谢谢

最佳答案

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

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

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

<build><finalname>blahblah

关于java - Spring MVC 应用程序在 "incorrect"URL 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9278258/

相关文章:

java - Spring 单击按钮时如何重定向以及单击另一个按钮时如何打印到控制台?

java - 从集合中查找 2d 中点之间的最短路线

java - Spring Boot注册服务器(Eureka服务器)

java - 使用 fx :root using FXML 内的列初始化 TableView

java - 在没有 Spring 的情况下注入(inject)应用程序属性

java - Libgdx、使用 Shader 的 alpha 文本标签在 Action 内创建标签时应用时不起作用

java - 如何在 spring 框架中编码 url?

java - 如何在 Mongodb (Spring) 上编写此聚合查询

java - 如何在 Spring MVC Controller 中接收多部分/表单数据?

spring - 如何使 @Controller 映射路径可配置?