2012-02-14 90 views
0

我正在與其他人一起使用Spring MVC Web應用程序。如果我運行應用程序,它使用URL http://localhost:8080/mywebapp,但如果其他人運行它,應用程序使用URL http://localhost:8080/xSpring MVC應用程序在「不正確的」URL上運行

是否有任何配置可以讓應用程序在特定的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> 

我是相當新的這一點,如果有任何信息丟失,請讓我知道。

感謝

回答

2

其在tomcat中的server.xml中定義:

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

如果使用war文件,war文件本身的名稱(你可以右鍵點擊一個重命名),而如果使用maven設置在POM:

<build><finalname>blahblah

+0

我想這個問題是,我們沒有在任何地方定義它。無論是在server.xml還是在pom中。 thx我會嘗試它。 – KenavR 2012-02-14 14:24:34