2016-02-05 83 views
0

我创建了spring-hibernate web应用程序,它在jetty服务器上运行完美。在jetty和tomcat上运行spring hibernate web appliction

但是,当我在tomcat上运行它时,它运行成功并没有错误,但我无法在Web浏览器上使用该应用程序,Web浏览器上没有任何内容显示(甚至没有出现错误)。

以下是详细信息: -

这就是应用程序成功启动使用Jetty服务器。

http://localhost:8080/contacts

这是我已经定义了相同的控制器。

@Controller 
public class ContactController { 

    @Autowired 
    private ContactRepository contactRepository; 

    @RequestMapping(value = "/contacts", method = RequestMethod.GET) 
    public String getContactList(Model model) { 
     model.addAttribute("contacts", contactRepository.findAll()); 
     return "contact/list"; 
    } 

} 

web.xml文件。

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


    <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>jsp</servlet-name> 
     <url-pattern>/view/*</url-pattern> 
    </servlet-mapping> 

    <filter> 
     <filter-name>openEntityManagerInViewFilter</filter-name> 
     <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class> 
     <init-param> 
      <param-name>entityManagerFactoryBeanName</param-name> 
      <param-value>entityManagerFactory</param-value> 
     </init-param> 
    </filter> 

    <filter-mapping> 
     <filter-name>openEntityManagerInViewFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

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

</web-app> 

下面是弹簧servlet.xml文件

<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.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 

    <mvc:annotation-driven /> 
    <context:component-scan base-package="com.marakana.contacts.controllers" /> 

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

回答

1

也许对Tomcat的网址应该是http://localhost:8080/yourWarName/contacts

+0

那么它是怎样工作的。我的意思是,为什么没有把它要求受战争名字在码头的情况下? –

+1

默认情况下,jetty也应该问战争名称,因为您可以部署多个应用程序。 https://www.eclipse.org/jetty/documentation/9.3.0.v20150612/automatic-webapp-deployment.html – achist

+0

我没有做任何事情..刚刚在pom.xml中提到jetty,当我运行我的应用程序使用maven它工作.. –

相关问题