Java 源服务器没有找到目标资源的当前表示,或者不愿意透露一个存在。关于部署到 tomcat
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43590008/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat
提问by Blaze
I have built an application using Spring with Eclipse IDE. When I launch the project from Eclipse IDE everything is fine but when I package the maven project as a war file and deployed to separate tomcat I have this issue
我已经使用 Spring 和 Eclipse IDE 构建了一个应用程序。当我从 Eclipse IDE 启动项目时,一切都很好,但是当我将 maven 项目打包为一个 war 文件并部署到单独的 tomcat 时,我遇到了这个问题
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
This is a configuration snippet from my xml file
这是我的 xml 文件中的配置片段
<!-- View Resolver -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/pages/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
I am trying to access this controller
我正在尝试访问此控制器
@RequestMapping(value = {"/welcome", "/"})
public String defaultPage() {
return "Web Service data successfuly consumed";
}
anyone with an idea why this is failing on deployed to tomcat?
任何人都知道为什么这在部署到 tomcat 时失败?
回答by Buffy Underrun
Trying to run a servlet in Eclipse (right-click + "Run on Server") I encountered the very same problem: "HTTP Status: 404 / Description: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists." Adding an index.html did not help, neither changing various settings of the tomcat.
尝试在 Eclipse 中运行 servlet(右键单击 +“在服务器上运行”)我遇到了同样的问题:“HTTP 状态:404/描述:源服务器没有找到目标资源的当前表示或不愿意揭示一个存在。” 添加 index.html 没有帮助,也没有改变 tomcat 的各种设置。
Finally, I found the problem in an unexpected place: In Eclipse, the Option "Build automatically" was not set. Thus the servlet was not compiled, and no File "myServlet.class" was deployed to the server (in my case in the path .wtpwebapps/projectXX/WEB-INF/classes/XXpackage/). Building the project manually and restarting the server solved the problem.
最后,我在一个意想不到的地方发现了问题:在Eclipse中,没有设置选项“自动构建”。因此 servlet 没有被编译,并且没有文件“myServlet.class”被部署到服务器(在我的例子中在路径 .wtpwebapps/projectXX/WEB-INF/classes/XXpackage/)。手动构建项目并重新启动服务器解决了问题。
My environment: Eclipse Neon.3 Release 4.6.3, Tomcat-Version 8.5.14., OS Linux Mint 18.1.
我的环境:Eclipse Neon.3 Release 4.6.3,Tomcat-Version 8.5.14.,OS Linux Mint 18.1。
回答by Ryan D
I've received the same error when working in a Spring Boot Application because when running as Spring Boot, it's easy to do localhost:8080/hello/World
but when you've built the artifact and deployed to Tomcat, then you need to switch to using localhost:8080/<artifactName>/hello/World
在 Spring Boot 应用程序中工作时,我收到了同样的错误,因为当作为 Spring Boot 运行时,这很容易做到,localhost:8080/hello/World
但是当您构建工件并部署到 Tomcat 时,您需要切换到使用localhost:8080/<artifactName>/hello/World
回答by Rudy
If it is maven project do Maven Update will solve the problem - Right Click on Project --> Maven --> Update Project and start your project normally.
如果是maven项目,做Maven Update就可以解决问题——右键Project --> Maven --> Update Project,正常启动你的项目。
回答by Akshay Kumar
solution one:Change the version of apache tomcat (latest one is preferred) (manual process).
解决方案一:更换apache tomcat版本(最好是最新的)(手动过程)。
solution two:Install latest eclipse IDE and configure the apache tomcat server (internally automatic process i,e eclipse handles the configuration part).
解决方案二:安装最新的eclipse IDE并配置apache tomcat服务器(内部自动流程i,e eclipse处理配置部分)。
After successful procedure of automatic process, manual process shall be working good.
自动加工程序成功后,手动加工应能正常工作。
回答by Tadele Ayelegn
I struggled with this problem many times.
我在这个问题上挣扎了很多次。
The solution I am currently using is weather the webapp(or the folder where you kept the views like jsp) is under deployment assembly.
我目前使用的解决方案是 web 应用程序(或您保存视图如 jsp 的文件夹)处于部署程序集之下。
To do so Right click on the project > Build Path > Configure Build path > Deployment Assembly > Add(right hand side) > Folder > (add your jsp
folder. In default case it is src/main/webapp
)
这样做Right click on the project > Build Path > Configure Build path > Deployment Assembly > Add(right hand side) > Folder > (add your jsp
文件夹。在默认情况下是src/main/webapp
)
You could also get this error after you did everything correct but on the JSP you put the anchor tag the old fashion(I am adding this incase if it help anybody else with the same issue).
在您正确完成所有操作后,您也可能会收到此错误,但在 JSP 上,您将锚标记放置为旧方式(如果它可以帮助其他遇到相同问题的人,我将添加此内容)。
I had the following syntax on the jsp. <a href="/mappedpath">TakeMeToTheController</a>
and I kept seeing the error mentioned in the question. However changing the tag into the one shown below solved the issue.
我在jsp上有以下语法。<a href="/mappedpath">TakeMeToTheController</a>
我一直看到问题中提到的错误。但是,将标签更改为如下所示的标签解决了该问题。
<a href=" <spring:url value="/mappedpath" /> ">TakeMeToTheController</a>
回答by Aiyaz Sattar
In Eclipse go to Project--> click on build automatically after that u try to execute
在 Eclipse 中转到 Project--> 在您尝试执行之后自动单击构建
回答by krati
I am also facing the same issue and i resolve it by putting web.xml file and the applicationcontext.xml file in WEB-INF folder.
我也面临同样的问题,我通过将 web.xml 文件和 applicationcontext.xml 文件放在 WEB-INF 文件夹中来解决它。
Hope this helps :)
希望这可以帮助 :)
回答by JEETHESH KARKERA
If you are developing spring boot application add "SpringBootServletInitializer" as shown in following code to your main file. Because without SpringBootServletInitializer Tomcat will consider it as normal application it will not consider as Spring boot application
如果您正在开发 Spring Boot 应用程序,请将以下代码中所示的“SpringBootServletInitializer”添加到您的主文件中。因为没有 SpringBootServletInitializer Tomcat 会将其视为普通应用程序,因此不会将其视为 Spring Boot 应用程序
@SpringBootApplication
public class DemoApplication extends *SpringBootServletInitializer*{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoApplication .class);
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication .class, args);
}
}
回答by eVader
I was facing same problem.
我面临同样的问题。
When I rightclick-> run on server then select my server manually it worked.
当我右键单击-> 在服务器上运行然后手动选择我的服务器时,它起作用了。
Do
做
Alt+Shift+X
then mannually select your server. It might help.
然后手动选择您的服务器。它可能会有所帮助。
回答by Rakeshwar Verma
Almost same problem get resolved by creating a geoexplorer.xml file in /opt/apache-tomcat-8.5.37/conf/Catalina/localhost content of geoexplorer.xml file is
通过在 /opt/apache-tomcat-8.5.37/conf/Catalina/localhost 中创建 geoexplorer.xml 文件来解决几乎相同的问题 geoexplorer.xml 文件的内容是
<Context displayName="geoexplorer" docBase="/usr/share/opengeo/geoexplorer" path="/geoexplorer"/>