I have an application with one Spring #Controller annotated with #RequestMapping.
Using Spring (core and webmvc) 4.1.0.RELEASE or higher I'm getting exception when starting the app server.
java.lang.NoSuchMethodError: org.springframework.web.bind.annotation.RequestMapping.name()Ljava/lang/String;
at method RequestMappingHandlerMapping.createRequestMappingInfo(RequestMapping annotation, RequestCondition<?> customCondition)
Debugging, using Eclipse inspect, the method variable annotation does not contains name attribute and fails at action annotation.name(). All the other attributes values are correct (they have the values defined in the Controller method annotated with #RequestMapping).
I'm using Tomcat 7 and Maven 2.3.
mvn dependency:tree does not shows other Spring version than 4.1.0.RELEASE.
The error does not occurs when using Spring 4.0.7.RELEASE or lower.
Does anyone have any clue?
Seems like a classpath issue. An old version of RequestMapping was being loaded.
Related
Good day,
I am doing a Spring Boot Application in my Eclipse IDE. When I right click on my SpringBoot Application file and run as Java application, I hitting error as follow:
APPLICATION FAILED TO START
Description:
Field tutorialRepository in com.utility.tool.ToolApplication required a bean of type 'com.utility.tool.repository.TutorialRepository' that could not be found.
The injection point has the following annotations:
- #org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.utility.tool.repository.TutorialRepository' in your configuration.
Then I found that I forget to include the spring boot starter data jar. Hence, I add the following code in my build.gradle and it finally run correctly:
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.7.5'
Then I right click my project and export jar as runnable jar, and then try to run it by java -jar my.jar, and it hit back the error.
I open the jar in JdGui, and found that the spring-boot-starter-data-jpa-2.7.5.jar is inside. May I know what is my mistake? My jar structure is something as follow:
The jar is in the list but is at bottom, thus not in my screen shot.
Check your SpringBoot annotations. You may be missing some #Service, #Repository, #Component annotations.
I have this (https://github.com/Danix43/HerculesAPI) REST application made by Java with Spring Boot.
All good when for some reason the #SpringBootApplication annotation doesn't find anymore the interfaces TermometruService annothed with #Service.
I have tried everything from using #ComponentScan with the service package but then any Rest operation returns a RESOURCE_NOT_FOUND to changing the jdk version and a flush of maven repositories.
Project structure if useful
The log after running the application
2020-01-27 19:33:39.635 DEBUG 6248 --- [main] o.s.c.a.ClassPathBeanDefinitionScanner : Ignored because not a concrete top-level class: file [D:\Programe\Programare\Java\HerculesAPI\target\classes\com\herculesapi\services\TermometruService.class]
The problem was solved by annotating the TermometruServiceImple class with #Service. Also regarding the Github repository, it doesn't always have all the changes right away pushed but yes the TermometruService interface had the annotation.
I have been using the below property in the application.properties file with spring-boot.version 1.5.6.RELEASE without any issues.
server.servletPath=/*
This was a workaround to enable a method in a library class which uses the function getPathInfo() of javax.servlet.http.HttpServletRequest to get a valid value instead of null.
I had to go with this workaround since there is no support of that library jar anymore.
This workaround started failing when I upgraded my application to spring-boot.version 2.1.7.RELEASE
server.servletPath is changed to spring.mvc.servletPath from Spring Boot 2 onwards.
I tried setting the below property and it did not work
spring.mvc.servletPath=/*
I also tried the below function in my configuration class and it did not work.
#Bean
public DispatcherServletRegistrationBean dispatcherServletRegistration(
DispatcherServlet dispatcherServlet,
ObjectProvider<MultipartConfigElement> multipartConfig) {
DispatcherServletRegistrationBean registration = new DispatcherServletRegistrationBean(
dispatcherServlet, "/*");
registration.setName("dispatcherServlet");
registration.setLoadOnStartup(-1);
multipartConfig.ifAvailable(registration::setMultipartConfig);
return registration;
}
Could you please provide a working solution for this property using spring-boot.version 2.1.7.RELEASE?
Thanks,
Dhinu
The correct setting for newer spring versions is:
spring.mvc.servlet.path=/some/path
This changes the mapping of the DispatcherServlet, so all resources served by spring are mapped to this path.
If you set:
server.servlet.contextPath=/some/path
The whole web context is changed.
The main difference is that setting the dispatcher servlet path allows you to register additional servlets on other paths while with context path set, spring boot's tomcat can only serve content below that context path.
Use the following config property on latest spring boot version:
server.servlet.contextPath=/*
We have recently migrated Spring Boot from 1.5 to 2.0. After migration, when I run the application, custom context listener is called and in it if we add a property source before a source that is not yet created, then it stops the application with exit code 1.
With Spring Boot 1.5.x, ConfigFileApplicationListener adds applicationConfigurationProperties to list of available property source.
For some reason, applicationConfigurationProperties is not getting added after migration and because of that following code fails:
event.getEnvironment().getPropertySources().addBefore("applicationConfigurationProperties", new MapPropertySource("aws", parameters));
With Spring 1.5.x
o.s.w.c.s.StandardServletEnvironment:Adding PropertySource 'aws' with search precedence immediately higher than 'applicationConfigurationProperties'
I enabled the following logs as well but don't see any exception:
logging.level.org.springframework=TRACE
logging.level.org.springframework.context=TRACE
logging.level.org.springframework.boot=TRACE
logging.level.org.springframework.core=TRACE
All application listeners implement ApplicationListener<ApplicationEnvironmentPreparedEvent>.
I checked the migration guide and found that a new event is added, ApplicationStartedEvent but that should not make any difference.
There's no property source named applicationConfigurationProperties in Spring Boot 2. The names of property sources derived from a configuration file now include details of where the file was found. For example, if you have an application.properties file at the root of the classpath, you will have a property source named applicationConfig: [classpath:/application.properties].
I'm having hibernate3.jar and hibernate-core-4.2.0.CR1.jar in my classpath and I'm using Spring 3.1.3 version. Code got compiles sucessfully but while runtime I'm getting following error
2014-10-28 10:51:25,174 DEBUG [RMI TCP Connection(2)-10.126.30.203] -
Target method failed for RemoteInvocation: method name
'getPriceByKeys'; parameter types [java.util.List, java.util.Date]
java.lang.NoSuchMethodError:
org.hibernate.SessionFactory.openSession()Lorg/hibernate/Session;
I google it but not find any solution. Please note : My project needs hibernate3.jar but at the same time my project dependent on some other 3rd party jar which inturn using hibernet4.2.0 jar.
Any help Pls ??
You need to remove multiple hibernate JAR files from your classpath. Without doing this, your application may not work as you expect; which means you need to migrate the hibernate version of your application from 3 to 4.1.
Although Spring 3.1 uses Hibernate 3 JAR files, you can still migrate to Hibernate 4. Check out Spring blog gives a small tutorial to do so.
Migrating to Spring 3.1 and Hibernate 4.1
As part of the Core-Spring course, we have a lab application that we
use to show how to integrate Spring and JPA/Hibernate together. We
have just upgraded it to Spring 3.1 / Hibernate 4.1, and thought we
should share a few tips.
Just an update. The cause of problem is , I'm having two spring-context xml files in project (one of my project and one related to another module that I'm integrating). I'm loading context xmls from two different classes. So one of the DAO class loaded by one of spring-context xml not getting the hibernate Session.
Later on using import tag, I included 2nd spring application context file in 1st application context file and then loaded a Single application context file from the class. It solved the error.
Thanks,