The origin server did not find the current representation of the target resource or does not want to disclose that it exists. when deployed to tomcat

I created an application using Spring with the Eclipse IDE. When I run the project from the Eclipse IDE, everything is fine, but when I pack the maven project as a war file and deploy to tomcat to split, I have this problem

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 fragment of the configuration from my XML file

 <!-- 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 happens when deploying to tomcat?

+14
source share
13 answers

I have struggled with this problem many times.

The solution I am currently using is that the web application (or the folder where you saved the views, for example jsp) is in the process of deployment.

To do this, Right click on the project > Build Path > Configure Build path > Deployment Assembly > Add(right hand side) > Folder > (add your jsp folder Right click on the project > Build Path > Configure Build path > Deployment Assembly > Add(right hand side) > Folder > (add your jsp . In the default case, this is src/main/webapp )

You can also get this error after everything was done correctly, but in the JSP you added the anchor label in the old way (I am adding this case if this helps someone else with the same problem).

I had the following syntax in JSP. <a href="/mappedpath">TakeMeToTheController</a> and I continued to see the error mentioned in the question. However, changing the tag to the one shown below solved the problem.

 <a href=" <spring:url value="/mappedpath" /> ">TakeMeToTheController</a> 
+9
source

I got the same error while working in the Spring boot application, because when starting as Spring Boot it is easy to execute localhost:8080/hello/World , but when you created the artifact and deployed it to Tomcat, then you need to switch to using localhost:8080/<artifactName>/hello/World

+5
source

If you are developing a spring boot application, add SpringBootServletInitializer, as shown in the following code, to your main file. Because without SpringBootServletInitializer, Tomcat would treat it like a normal application that would not be considered a Spring boot application.

 @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); } } 
+3
source

I also ran into the same problem, and I solved it by putting the web.xml file and applicationcontext.xml in the WEB-INF folder.

Hope this helps :)

+1
source

Attempting to start a servlet in Eclipse (right-click + "Run on server"). I encountered the same problem: "HTTP status: 404 / Description: the origin server did not find the current representation of the target resource or does not want to disclose that it exists." Adding index.html did not help without changing various tomcat settings.

Finally, I found the problem in an unexpected place: in Eclipse, the Create Automatically option was not set. Thus, the servlet was not compiled, and the file "myServlet.class" was not added to the server (in my case, the path is .wtpwebapps / projectXX / WEB-INF / classes / XXpackage /). Manually building the project and restarting the server solved the problem.

My environment: Eclipse Neon.3 Release 4.6.3, Tomcat-Version 8.5.14., Linux Mint 18.1.

0
source

If this is a maven project, Maven Update solves the problem - right-click Project β†’ Maven β†’ Update Project and start your project as usual.

0
source

one solution: Change the version of apache tomcat (the latter is preferred) (manual process).

solution two: Install the latest eclipse development environment and configure the apache tomcat server (internally automatic process i, e eclipse processes part of the configuration).

After a successful automatic process, the manual process should work well.

0
source

In Eclipse, go to Project β†’ click on the assembly automatically after that u try to run

0
source

I ran into the same problem.

When I rightclick-> run on the server, I select my server manually, it works.

Make

 Alt+Shift+X 

then manually select your server. This can help.

0
source

Almost the same problem can be solved by creating the geoexplorer.xml file in /opt/apache-tomcat-8.5.37/conf/Catalina/localhost the contents of the geoexplorer.xml file

 <Context displayName="geoexplorer" docBase="/usr/share/opengeo/geoexplorer" path="/geoexplorer"/> 
0
source

I ran into the same problem, and with some help from @tadtab's answer, I was able to find a solution for the same problem in my project.

Steps:

1-> Follow the steps mentioned in @tadtab answers.

2-> Right-click on project-> Click Properties-> Find Deployment Assembly.

3-> Search if your folder exists on the screen. (If not, add it).

4-> On the screen, you will find the β€œDeployment Path” column corresponding to your source folder. Copy this path. In my case it was / views.

enter image description here 5-> Thus, in principle, in the setPrefix () method , we should have a path during deployment. Previously, I just used / views in the setPrefix () method , so I got the same error. But after that everything worked.

 @Bean public ViewResolver viewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/WEB-INF/classes/"); resolver.setSuffix(".jsp"); resolver.setExposeContextBeansAsAttributes(true); return resolver; } 

The same should apply to the XML configuration.

0
source

This problem may occur even when you try to start a project from the controller page. Launch your project from the JSP page. Go to your JSP page; right click -> Run As-> Run on Server. I ran into the same problem. I started my project from the controller page. Launch your project from the JSP page.

0
source

Your dispatch servlet does not indicate where to send the request. The problem is that your controller component is not created / does not work.

Even I ran into the same problem. Then added the following to mvc-config.xml

 <mvc:annotation-driven/> <context:component-scan base-package="com.nsv.jsmbaba.teamapp.controller"/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"><value>/WEB-INF/view/</value></property> <property name="suffix"><value>.jsp</value></property> </bean> 

Hope this helps

0
source

Source: https://habr.com/ru/post/1267095/


All Articles