Blaze
Blaze

Reputation: 2329

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

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

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

<!-- 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?

Upvotes: 24

Views: 198781

Answers (15)

Aiyaz Sattar
Aiyaz Sattar

Reputation: 9

I am facing the error like The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

In Eclipse right click on project and click on Build then try to run as server. It will work fine for me

Upvotes: 0

mumbasa
mumbasa

Reputation: 822

Check to find the root cause by reading logs in the tomcat installation log folder if all the above answers failed.Read the catalina.out file to find out the exact cause. It might be database credentials error or class definition not found.

Upvotes: 0

my-
my-

Reputation: 624

Check Java versions That was a problem for me. IDE (Intellij in my case) could launch without the problem, but when I tried to run war inside tomcat docker image app didn't work. The reason was docker image had a different (lower) version compare to the development environment. There were no errors messages indicating any of this.

Upvotes: 0

Naga
Naga

Reputation: 866

Your dispatcher servlet does not where to dispatch the request. Issue is your controller bean is not created/working.

Even I faced the same problem. Then added the following under 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

Upvotes: 0

Smitha
Smitha

Reputation: 21

This issue can even occur when you try to run your project from controller page. Run your project from the jsp page. Go to your jsp page; right-click->Run As->Run on Server. I faced the same issue.I was running my project from the controller page. Run your project from jsp page.

Upvotes: 1

Deep
Deep

Reputation: 959

I was facing the same issue and with some hint from @tadtab 's answer, I was able to figure out a solution for the same problem in my project.

Steps:

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

2->Right Click on the project->Click on Properties->Search for Deployment Assembly.

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

4->On the screen you will find a 'Deploy Path' column corresponding to your source folder. Copy that path. In my case, it was /views.

enter image description here 5->So basically, in the setPrefix() method, we should have the path at the time of deployment. Earlier I was just using /views in the setPrefix() method, so I was getting the same error. But after, it worked well.

@Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();

        resolver.setPrefix("/WEB-INF/classes/");
        resolver.setSuffix(".jsp");

        resolver.setExposeContextBeansAsAttributes(true);
        return resolver;

    }

The same should be applicable to XML configuration also.

Upvotes: 2

Rakeshwar Verma
Rakeshwar Verma

Reputation: 1

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

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

Upvotes: 0

Elif
Elif

Reputation: 355

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.

Upvotes: 0

Tadele Ayelegn
Tadele Ayelegn

Reputation: 4706

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.

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)

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).

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.

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

Upvotes: 13

JEETHESH KARKERA
JEETHESH KARKERA

Reputation: 203

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

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

Upvotes: 11

krati
krati

Reputation: 43

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.

Hope this helps :)

Upvotes: 1

Akshay Kumar
Akshay Kumar

Reputation: 11

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

solution two: Install latest eclipse IDE and configure the apache tomcat server (internally automatic process i,e eclipse handles the configuration part).

After successful procedure of automatic process, manual process shall be working good.

Upvotes: 0

Rudy
Rudy

Reputation: 749

If it is maven project do Maven Update will solve the problem - Right Click on Project --> Maven --> Update Project and start your project normally.

Upvotes: 0

Ryan D
Ryan D

Reputation: 1113

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

Upvotes: 12

Buffy Underrun
Buffy Underrun

Reputation: 41

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.

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.

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

Upvotes: 4

Related Questions