我已经创建了一个 spring-hibernate web 应用程序,它在 jetty 服务器上完美运行。
然而,当我在 tomcat 上运行它时,它成功运行,没有错误,但我无法在网络浏览器上使用该应用程序,网络浏览器上没有任何显示(甚至没有错误)。
详情如下:
这是应用程序成功开始使用 jetty 服务器的地方。
这是我为其定义 Controller 的地方。
@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>
下面是spring-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>
最佳答案
也许对于 tomcat url 应该是 http://localhost:8080/yourWarName/contacts
关于java - 在 jetty 和 tomcat 上运行 spring hibernate web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35217647/