• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

The problem with RestController  RSS feed

 
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am posting again because I found problems after I closed my post as complete. I was trying to use @RestController in a spring application but I couldn't find the import. The answer was that I should have
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>5.1.0.RELEASE</version>
</dependency>
I changed <spring.version>3.1.2.RELEASE</spring.version> to <spring.version>5.1.0.RELEASE</spring.version> updated the project in maven and then I could use @RestController in my code.

However something incredible happened; when I ran the application I started getting 404 error "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists." . Strangely, the problem hapened before I update the project with Maven. The problem also happened with Pivota tc Server, or with a new server. I have had this problem before for several days and I haven't been able to find a solution. Of course, if I revert the change in <spring.version> the problem disapears.
On the other hand, if I only change the version for spring-web (which was my original problem) I am now getting the errors
Description Resource Path Location Type
The project was not built since its build path is incomplete. Cannot find the class file for org.springframework.context.annotation.AnnotationConfigRegistry. Fix the build path then try building this project Spring Data Chapter-2 Unknown Java Problem
The type org.springframework.context.annotation.AnnotationConfigRegistry cannot be resolved. It is indirectly referenced from required .class files DataJPAExampleInitializer.java /Spring Data Chapter-2/src/main/java/com/packtpub/springdata/jpa/config line 26 Java Problem

I am totally confused.

 
Master Rancher
Posts: 3673
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AT what point are you getting errors?

Does the project build correctly?

Does this only happen when you deploy and try and run it on Tomcat?
 
Alejandro Barrero
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your interest Dave. The problem with the 404 error "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists." occurred inmediatelly after i made the change in the pom; the problem also happened with Pivotal tc Server, or with a new server. Since trying the Rest controller with "http://localhost:8080/chapter-02/hello" gives the same result; it appears that the view resolver has been affected. I haven't build the project; it is build by updating the project with Maven or by changing the code in the rest controller.
 
Alejandro Barrero
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just noticed that running the server has the errors
SEVERE: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.packtpub.springdata.jpa.config.ApplicationContext: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/persistence/Converter

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/persistence/Converter
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)

Caused by: java.lang.NoClassDefFoundError: javax/persistence/Converter
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.<clinit>(DefaultPersistenceUnitManager.java:125)

Caused by: java.lang.ClassNotFoundException: javax.persistence.Converter
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1309)
 
Alejandro Barrero
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strange things happening. I changed to <spring.version>4.3.0.RELEASE</spring.version> because I though 5 was too advanced and lo and behold, the application runs! However, the rest controller

doesn't run; I am running "http://localhost:8080/chapter-02/hello" with a post request in Postman, bu I am getting "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists." I still have the same problem even if I change the controller to "RequestMethod.GET".
 
Ranch Hand
Posts: 118
1
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. While making update to version, make sure you have version present in the Maven repository.
2. Also make sure while making the changes to the certain module, make sure other modules which are used by this module or by application also get updated or compatible with it.(This is my personal observation, kind of problem I have also faced)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!