- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在域下的 OpenShift 上使用 Spring MVC 运行 Tomcat7 应用程序:financial-datasite.rhcloud.com .我使用 Tomcat 服务器在本地运行和测试应用程序,然后将其推送到远程存储库。目前,只有一个主页和一个重定向到不同页面的按钮。在本地测试时,两个页面都按预期显示内容。但是,当部署到远程服务器时,只显示主页,单击按钮时,出现 HTTP 404 错误。我在这里遇到过各种类似的问题,但到目前为止都没有帮助。我尝试过配置 web.xml、pom.xml、servlet-context.xml 和 Controller 文件。然而,这些都没有帮助。我也一直在检查 tail files and logs监视正在发生的事情,这表明远程服务器正在访问第二页 Controller 类中的某些“printWelcome”方法(我的项目中甚至不存在):
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/Sectors],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.spring.mvc.SectorController.printWelcome(org.springframework.ui.ModelMap)
这是我的 project structure .在我的本地主机中,默认页面以 localhost:8181/mvc/
运行,第二个页面以 http://localhost:8181/mvc/Sectors
运行。同样,部署后,主页运行为 http://financial-datasite.rhcloud.com第二页执行为 http://financial-datasite.rhcloud.com/Sectors ,这会为/WEB-INF/views/hello.jsp 引发 404 错误,同样,它甚至不存在于我的项目目录中。我在日志文件中观察到的另一件事是,代码可能没有命中 SectorController 类,因为我已经为要记录的打印命令编写了代码,当从已部署站点请求页面时,这些命令并没有真正登录到控制台中。我非常不确定远程服务器上正在运行哪些文件,以及是否存在我不知道的任何配置问题。以下是我调用新页面加载的 web.xml、pom.xml、servlet-context.xml、Sectors.jsp、Google-Maps.js)和 SectorController.java(这是用于的 Controller 文件第二页)。很抱歉问题很长,如果您需要更多信息,请告诉我。任何帮助将不胜感激,谢谢。
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>Financial Data Site</display-name>
<servlet>
<servlet-name>financial</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>financial</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
</web-app>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.spring</groupId>
<artifactId>mvc</artifactId>
<name>SpringMVC</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.6</java-version>
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
<!-- Newly Added from here -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>eap</id>
<url>http://maven.repository.redhat.com/techpreview/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>eap</id>
<url>http://maven.repository.redhat.com/techpreview/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<!-- Till here -->
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.10.Final</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>
<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- JSTL -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>compile</scope>
</dependency>
<!-- Tag Library -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
<scope>compile</scope>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- When built in OpenShift the 'openshift' profile will be
used when invoking mvn. -->
<!-- Use this profile for any OpenShift specific customization
your app will need. -->
<!-- By default that is to put the resulting archive into the
'deployments' folder. -->
<!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
<id>openshift</id>
<build>
<finalName>financial</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<outputDirectory>webapp</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
servlet-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
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">
<annotation-driven />
<context:component-scan base-package="com.spring.mvc" />
<resources mapping="/resources/**" location="/resources/" />
<beans:bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
</beans:beans>
扇区.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ page session="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Sectors</title>
</head>
<body>
<h1>Message</h1>
<c:if test="${not empty Sectors}">
<ul>
<c:forEach var="_SectorNames" items="${Sectors}">
<li>${_SectorNames}</li>
</c:forEach>
</ul>
</c:if>
</body>
</html>
Google-Maps.js:以下代码片段仅包含用于在 map 上创建 div 部分和在新窗口上调用新页面的函数
function HomeControl(controlDiv, map)
{
// Set CSS for the control border.
var _ControlUI = document.createElement('div');
_ControlUI.style.backgroundColor = '#fff';
_ControlUI.style.border = '2px solid #fff';
_ControlUI.style.borderRadius = '3px';
_ControlUI.style.boxShadow = '0 2px 6px rgba(0,0,0,.3)';
_ControlUI.style.cursor = 'pointer';
_ControlUI.style.marginBottom = '22px';
_ControlUI.style.textAlign = 'center';
_ControlUI.title = 'Click to filter by Sectors';
controlDiv.appendChild(_ControlUI);
// Set CSS for the control interior.
var _ControlText = document.createElement('div');
_ControlText.style.color = 'rgb(25,25,25)';
_ControlText.style.fontFamily = 'Roboto,Arial,sans-serif';
_ControlText.style.fontSize = '12px';
_ControlText.style.lineHeight = '38px';
_ControlText.style.paddingLeft = '5px';
_ControlText.style.paddingRight = '5px';
_ControlText.innerHTML = '<strong>View by Sectors</strong>';
_ControlUI.appendChild(_ControlText);
// Setup the click event listeners, also calls Sectors page on a new window
google.maps.event.addDomListener(_ControlUI, 'click', function() {
//add code here to redirect to Sectors page
var _Window = window.open('/mvc/Sectors', '__blank');
_Window.focus();
});
}
扇区 Controller .java
package com.spring.mvc;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.spring.dao.impl.SectorDAOImpl;
import com.spring.model.Sector;
@Controller
public class SectorController {
private static final Logger logger = LoggerFactory.getLogger(SectorController.class);
@RequestMapping(value = "/Sectors", method = {RequestMethod.HEAD, RequestMethod.GET})
public ModelAndView DisplaySectors(Locale locale, Model model) {
logger.info("Welcome home! You are in: {}.", locale);
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate );
SectorDAOImpl _SectorDAOImpl = new SectorDAOImpl();
List<Sector> _Sectors = _SectorDAOImpl.GetByID();
List<String> _SectorNames = new ArrayList<String>();
for( Sector sector : _Sectors) {
_SectorNames.add(sector.getSectorName());
}
ModelAndView _ModelAndView = new ModelAndView("Sectors");
_ModelAndView.addObject("Sectors", _SectorNames);
return _ModelAndView;
}
}
最佳答案
正如 Jessai 在评论中指出的那样,
var _Window = window.open('/mvc/Sectors', '__blank');
不要明确使用您的项目名称!有一些方法可以获取上下文名称,例如 HttpServletRequest 的 request.getContextPath() 方法。
在这种使用硬编码 URL 字符串的情况下,我认为您可以使用相对 URL,只需“Sectors”或“./Sectors”。
引用资料:
'__blank' :你的意思是 '_blank' ?
顺便说一句:
您正在 Tomcat 7 上部署,因此您可以在 web.xml
中声明遵守 Servlet 3.0 规范而不是 2.5。文件。
请参阅以下内容以在启动时禁用组件扫描:
https://wiki.apache.org/tomcat/HowTo/FasterStartUp#Configure_your_web_application
开启
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/Sectors],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.spring.mvc.SectorController.printWelcome(org.springframework.ui.ModelMap)
如果你的类文件与你的源代码不匹配,那就意味着你的代码没有被编译。删除已编译的类(例如使用 mvn clean
)并重试。
如果你很好奇,你可以用任何 ZIP 归档应用程序解压你的 war 文件,看看里面到底有什么。
您或我们公司是否拥有http://spring.com的域名?网站?如果不是,请勿使用包名称 com.spring
并且不要使用 <groupId>com.spring</groupId>
.这些名字不属于你。他们是别人的属性(property)。
开启
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
如果您使用的是 3.x,为什么不使用 3.x 系列中的当前 3.2.12.RELEASE,或者更好的最后一个 4.1.6.RELEASE? Spring Framework 3.1.x 的生命周期已结束,不再受支持。
关于java - Openshift Spring MVC Tomcat 应用程序的部署路径返回 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29881445/
我是 devops 的新手,并且正在阅读有关此的 openshift 文档。似乎 buildconfig 和 pipeline(openshift 4.6 中的 tekton)都可以实现 source
我正在寻找 OpenShift Origin 和 OpenShift Enterprise 之间的主要区别。我知道第一个是开源的,后者是商业版。与开源版本相比,OpenShift Enterprise
在 Openshift 上部署应用程序后,收集应用程序的 1) CPU、2) 网络、3) 内存、4) 磁盘存储使用情况的推荐方法/最佳实践是什么?基本上是为了监控应用程序。 如果它们能够以时间序列格式
几天来,我一直在尝试通过 Openshift 连接到我的应用程序,但仍然没有运气。 我现在不确定该去哪个论坛,因为我在任何地方都没有得到帮助。 1) 我通过终端运行sudo rhc setup (我之
Spinnaker 是否可以作为云提供商在 Red Hat 的 Openshift 上运行和部署应用程序? 如果没有,需要什么才能使之成为现实? 谢谢。 最佳答案 首先,您需要为 Openshift
我目前正在使用 Red Had 提供的免费培训来学习 Openshift 作为开发人员和管理员。你知道我可以用来获得“刺激”经验的任何其他地方吗?提前致谢。 :) 最佳答案 红帽提供的免费培训是一个良
我在 openshift 中创建应用程序时不小心选择了大齿轮。有没有办法在不重新创建我的应用程序的情况下降级齿轮类型?比如从大到中,甚至从大到小。highcpu。 提前谢谢各位 最佳答案 您确实必须重
我创建了一个 Web 应用程序,我想在 Openshift 上进行部署。 最简单的方法是什么?我正在使用 Openshift Eclipse 客户端。 我应该创建一个新的 openshift,然后从我
我想在 Openshift 中定义一条具有多条路径的路由,每条路径转发到不同的服务。例如/pathA 会将请求转发到 ServiceA ,而/pathB 会将请求转发到 ServiceB。 这在 Op
我想创建一个构建器图像 app_name:latest这将采用多个源输入,例如,另一个图像和二进制源,然后将输出创建到 app_name:latest . 示例 - { "kind": "Bu
我有一个 openshift 应用程序,我在本地彻底重新设计了该应用程序,并希望在 openshift 服务器上重新开始。 我可以删除所有齿轮并重做它们,但是有没有一种优雅的方法或任何方法可以将 op
大约一周以来,它说: Queued for provisioning Due to an increase in OpenShift Online Starter popularity, please
我希望我的部署配置使用作为构建配置输出的镜像。 我目前正在使用这样的东西: - apiVersion: v1 kind: DeploymentConfig metadata: anno
与 OpenShift Container Platform(以前的 Enterprise)相比,OpenShift Origin 是否有任何强制限制?我的意思是,像 Origin 这样的东西,你最多
一个 openshift 应用程序可以有多个域吗? Heroku 允许这样做。完全不同的域(app.abc.com、app.xyz.com)或子域(*.abc.com、*.xyz.com)。 open
我想开发一种新的墨盒供我自己使用。我使用 OpenShift Cartridge Development Kit 开始我的工作。我的构建脚本写在.openshift/action_hooks/buil
我正在使用 flask 。我安装了 Flask-migrate 并一直在使用它来迁移我的 postgresql 数据库。它在我的本地盒子上工作正常。但是,当我在 openshift 上运行它时出现错误
当我尝试在打开的类次项目中推送一些更改时,我在尝试构建项目时遇到了这个错误: remote: Found pom.xml... attempting to build with 'mvn --glob
在不可扩展的奇异齿轮中,齿轮空闲多长时间没有流量。我看过 https://access.redhat.com/site/documentation/en-US/OpenShift_Online/2.0
我试图在 OpenShift 中更新图像时触发部署。该图像托管在私有(private)外部 docker 注册表中。我创建了一个 ImageStream映射到这个外部图像。当我将新图像推送到注册表时,
我是一名优秀的程序员,十分优秀!