I currently have a Spring Boot application with a dependency to a Java module. This Java module has some classpath properties. When I #Autowired a bean from the Java module in my Spring Boot application and define this bean with a #Bean annotation and then run the Spring Boot application it will throw errors.
Error thrown:
2017-02-07 12:16:03.188 WARN 17620 --- [on(4)-127.0.0.1] ationConfigEmbeddedWebApplicationContext :
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'MyService': Unsatisfied dependency expressed through method 'setClassPathProperty' parameter 0; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'myClassPathProperties' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?
Property defined in Java Module
src/main/resources/myproject-context.xml
<util:properties id="myClassPathProperties" location="classpath:myproject.properties" />
Property usage in Java Module
#Value("#{myClassPathProperties['property.x']}")
public void setClassPathProperty(String x) {
this.x = x;
}
Bean definition in Spring Boot application
#Bean (name = "mailSubscriptionDao")
public MyService getMyService() {
return new MyServiceImpl();
}
Try to get the whole properties object injected
#Autowired
Properties myClassPathProperties;
If this works, you know you have loaded myproject-context.xml correctly.
Than you can also have a look with the debugger, whether a property with name 'property.x' exists or not.
Related
I ran the batch application in couple of linux environment. The application was working in one of the environment and is failing in other environment. I am getting the below failure message in that environment. The environment had some parameters which is blocking the application to start it seems. What needs to be done to change this and make the application work.
I checked the property file and found this parameter
'ENV=int'.
I think this might be the once causing the issue.
Error StackTrace:
{'timestamp': '2022-09-13 06:17:44,381','level':' WARN','transactionId':'','userId':'','env' :'','src_host':'','appId':'','className':'','methodName':'','messageId':'','message':'Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'btchJobLauncher': Unsatisfied dependency expressed through field 'jobs'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration': Unsatisfied dependency expressed through field 'dataSource'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cmnCnfg': Unsatisfied dependency expressed through field 'cnfgReader'; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'cnfgReader': Could not bind properties to 'CnfgReader' : prefix=, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'env' to org.springframework.core.env.Environment'}
{'timestamp': '2022-09-13 06:17:44,403','level':' INFO','transactionId':'','userId':'','env' :'','src_host':'','appId':'','className':'','methodName':'','messageId':'','message':'
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.'}
{'timestamp': '2022-09-13 06:17:44,440','level':'ERROR','transactionId':'','userId':'','env' :'','src_host':'','appId':'','className':'','methodName':'','messageId':'','message':'
APPLICATION FAILED TO START
Description:
Failed to bind properties under 'env' to org.springframework.core.env.Environment:
Property: env
Value: int
Origin: "ENV" from property source "systemEnvironment"
Reason: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [org.springframework.core.env.Environment]
Action:
Update your application's configuration.
I have added the code block where the stack trace was pointing the issue.
#Configuration
#EnableConfigurationProperties
#ConfigurationProperties
#PropertySource(value = "file:${PROPS_FILE:cnfg/BtchDb.properties}")
#Component
public class CnfgReader {
#Autowired
private Environment envt;
public Environment getEnvt() {
return envt;
}
public void setEnvt(Environment envt) {
this.envt = envt;
}
}
What changes I have to make in order to make the batch application run in the environment. Thanks in advance.
I'm using Spring Boot 1.5.2 and it has this annoying error which I could not understand the reason.
I have a Main class with these scanning configured:
#EnableJpaRepositories(basePackages = {"com.abc", "org.abc"})
#EntityScan(basePackages = {"com.abc", "org.abc", "abc"})
#ComponentScan(basePackages = {"com.abc", "org.abc", "abc"})
public class ApplicationMain extends SpringBootServletInitializer {
....
}
A model class
File: AbcUser.java
package com.abc.admin.model
#Entity
#Table(name = AbcUser.TABLE_NAME)
public class AbcUser {
}
And an interface class which extends CrudRepository:
File UserRespository.java inside this package.
package com.abc.repository.interfaces
#Repository
public interface UserRespository extends CrudRepository<AbcUser, Long> {
#Transactional
Long deleteByUsername(String username);
}
Now, when I tried to start the web application, it first has the warning which says, it cannot scand files...And then throws error, that the Bean cannot be found.
java -jar abc.war
WARN: Cannot search for matching files underneath URL [war:file:/home//tmp/build/applications/petascope/petascope_main/target/abc.war*/WEB-INF/classes/org/abc/] because it does not correspond to a directory in the file system
java.io.FileNotFoundException: URL [war:file:/home//tmp/build/applications/petascope/petascope_main/target/abc.war*/WEB-INF/classes/org/abc/] cannot be resolved to absolute file path because it does not reside in the file system: war:file:/home//tmp/build/applications/petascope/petascope_main/target/abc.war*/WEB-INF/classes/org/abc/
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:218)
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:52)
at org.springframework.core.io.UrlResource.getFile(UrlResource.java:213)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources(PathMatchingResourcePatternResolver.java:685)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:477)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:279)
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.buildDefaultPersistenceUnitInfo(DefaultPersistenceUnitManager.java:525)
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.readPersistenceUnitInfos(DefaultPersistenceUnitManager.java:505)
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:442)
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:426)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:325)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359)
at org.abc.MigrationBeanApplicationConfiguration.createEntityManagerFactory(MigrationBeanApplicationConfiguration.java:313)
Due to it cannot create Bean
ERROR [2021-08-23 16:32:17] TomcatStarter#63: Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'requestsFilter': Unsatisfied dependency expressed through field 'userRepositoryService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userRepositoryService': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRespository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.rasdaman.admin.model.RasdamanUser
WARN [2021-08-23 16:32:17] AnnotationConfigEmbeddedWebApplicationContext#550: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
ERROR [2021-08-23 16:32:17] SpringApplication#815: Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRespository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.abc.admin.model.AbcUser
I found the solution for the scanning problem which leads to the error of Bean not found from https://shekerama.wordpress.com/2017/03/25/how-to-solve-java-lang-illegalargumentexception-not-an-managed-type/.
final LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
entityManagerFactory.setPackagesToScan("com.abc", "org.abc");
I want my application to stop loading the database connection when launched in local environment and use Couchbase database when launched in Dev environment. So to start with it I have excluded CouchbaseDataAutoConfiguration -
#SpringBootApplication(exclude= {CouchbaseDataAutoConfiguration.class})
#EnableAspectJAutoProxy()
public class ABCAdapterApplication {
public static void main(String[] args) {
SpringApplication.run(ABCAdapterApplication.class, args);
}
}
And commented out the #Configuration from the AbstractCouchbaseConfiguration class
//#Configuration
public class ABCAdapterBucketConnection extends AbstractCouchbaseConfiguration{
/* buckets configuration here*/
}
After this I can see in the logs that Spring is not loading any database connection but it gives org.springframework.beans.factory.UnsatisfiedDependencyException -
{"timestamp":"2020-05-09 15:31:37.073","severity":"WARN","class":"org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext","crId":"","msg":"Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ABCAdapterRetrySourceRoute': Unsatisfied dependency expressed through field 'dataProcessor'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'persistDataProcessor': Unsatisfied dependency expressed through field 'repo'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.vu.payments.abc.adapter.repositories.KafkaPayloadRepository' available: expected at least 1 bean which qualifies as autowire candidate.}
Why the classes with #Repository annotation were not registered in Spring context when I had disabled couchbase auto-configuration ? How can I stop this application from failing to start-up even if there is no database connection when launched in local environment ?
There is a handler class which based on active profile instantiates a data loader class (FromFile or FromDatabase both implementing ConfigLoader i/f). When no profile is selected FromFile gets instantiated and this class makes no reference to any repository class or method that's why It should work even if database has not been loaded. I looked thoroughly and found that KafkaPayloadRepository is being referred directly in PersistDataProcessor. Direct reference to repository classes has to be avoided in this use case and ConfigLoader interface should be used instead.
I just started to work with Spring. I followd some tutorials to create a Spring Web MVC project which works. It is a simple project which displays some information as website using thymeleaf.
Now I wanted to add a couchbase database for storing data, I already worked with couchbase for simple .Net Apps. So I followed the tutorial on the official couchbase blog to create a service for the connection to couchbase. Couchbase with Spring-Boot and Spring Data
But when I try to autowire the service I get the following error message:
[main] INFO org.springframework.web.servlet.DispatcherServlet - Initializing Servlet 'dispatcher'
[main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate - Multiple Spring Data modules found, entering strict repository configuration mode!
[main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate - Bootstrapping Spring Data repositories in DEFAULT mode.
[main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 70ms. Found 1 repository interfaces.
[main] WARN org.springframework.web.context.support.AnnotationConfigWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'indexController': Unsatisfied dependency expressed through field 'buildingService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xplorg.model.BuildingService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
[main] ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'indexController': Unsatisfied dependency expressed through field 'buildingService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xplorg.model.BuildingService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
As far as I understand the message, found Spring the repository but it does not qualify as autowire candidate.
My WebConfig:
#Configuration
#EnableWebMvc
#ComponentScan("com.project.controller")
#ComponentScan("com.xplorg.model")
#EnableCouchbaseRepositories(basePackages = {"com.project.model"})
public class MvcWebConfig implements WebMvcConfigurer {
// Code for generating templateEngine/Resolver ...
}
My controller (here I try to autowire the service, not sure if it is the correct place, causes the exception):
#Controller
public class IndexController {
private int count = 0;
#Autowired
private BuildingService buildingService;
// This line causes the exception
#GetMapping("/")
public String index(Model model) {
model.addAttribute("message", "Welcome to Hello World");
return "index";
}
// Some more mapping no use of service
}
My BuildingService:
public interface BuildingService {
Building save(Building building);
Building findById(String buildingId);
List<Building> findByCompanyId(String companyId);
Building findByCompanyAndAreaId(String companyId, String areaId);
List<Building> findByCompanyIdAndNameLike(String companyId, String name, int page);
List<Building> findByPhoneNumber(String telephoneNumber);
Long countBuildings(String companyId);
}
My BuildingServiceImpl:
#Service("BuildingService")
public class BuildingServiceImpl implements BuildingService {
#Autowired
private BuildingRepository buildingRepository;
#Override
public List<Building> findByCompanyId(String companyId) {
return buildingRepository.findByCompanyId(companyId);
}
public List<Building> findByCompanyIdAndNameLike(String companyId, String name, int page) {
return buildingRepository.findByCompanyIdAndNameLikeOrderByName(companyId, name, new PageRequest(page, 20))
.getContent();
}
#Override
public Building findByCompanyAndAreaId(String companyId, String areaId) {
return buildingRepository.findByCompanyAndAreaId(companyId, areaId);
}
#Override
public List<Building> findByPhoneNumber(String telephoneNumber) {
return buildingRepository.findByPhoneNumber(telephoneNumber);
}
#Override
public Building findById(String buildingId) {
return buildingRepository.findById(buildingId).get();
}
#Override
public Building save(Building building) {
return buildingRepository.save(building);
}
#Override
public Long countBuildings(String companyId) {
return buildingRepository.countBuildings(companyId);
}
}
The order classes are simple copied from the tutorial.
Project sturcture:
src/main/java
com.project
config
MvcWebApplicationInitializer
MvcWebConfig
controller
IndexController
model
Area
Building
BuildingRepository
BuildingService
BuildingServiceImpl
EDIT
At the end of the error message the following line stands, could that mean I am missing a dependency?
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'couchbaseRepositoryOperationsMapping' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:769)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1221)
EDIT 2
After trying different approaches and reading more about Spring/Couchbase and Autowired, I now get the exception that No bean named 'couchbaseRepositoryOperationsMapping' available. The whole exception looks like this:
[main] INFO org.springframework.web.servlet.DispatcherServlet - Initializing Servlet 'dispatcher'
[main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate - Bootstrapping Spring Data repositories in DEFAULT mode.
[main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 63ms. Found 1 repository interfaces.
[main] WARN org.springframework.web.context.support.AnnotationConfigWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'buildingServiceImpl': Unsatisfied dependency expressed through field 'buildingRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'buildingRepository': 'buildingRepository' depends on missing bean 'couchbaseRepositoryOperationsMapping'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'couchbaseRepositoryOperationsMapping' available
[main] ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'buildingServiceImpl': Unsatisfied dependency expressed through field 'buildingRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'buildingRepository': 'buildingRepository' depends on missing bean 'couchbaseRepositoryOperationsMapping'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'couchbaseRepositoryOperationsMapping' available
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)
I'm using Spring Boot 2.1.1, Spring Data REST, Spring HATEOAS, Hibernate.
In my #Configuration class I created a custom RestTemplate:
#Configuration
#EnableRetry
#EnableTransactionManagement
#EnableJpaAuditing(auditorAwareRef = "springSecurityAuditorAware")
public class CustomConfiguration {
#Bean
public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplateBuilder().setConnectTimeout(httpClientConnectionTimeout)
.setReadTimeout(httpClientReadTimeout).build();
ObjectMapper objectMapper = new ObjectMapper();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter(objectMapper));
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
return restTemplate;
}
I use this restTemplate in a #Component:
#Component
public class TenantRestClient {
#Autowired
private RestTemplate restTemplate;
public Tenant register(Tenant tenant) {
//my stuff here
}
Until Spring Boot 2.0.3 everything worked fine, but if I update to Spring 2.0.4 or greater, when I try to run my application I've this exception:
14/12/2018 09:09:55,442 INFO main testServerApplication:50 - Starting testServerApplication on SVILUPPO1 with PID 10612 (C:\Users\Daniele\Documents\workspaceREST2\test-server\target\classes started by Daniele in C:\Users\Daniele\Documents\workspaceREST2\test-management-server)
14/12/2018 09:09:55,448 DEBUG main testServerApplication:53 - Running with Spring Boot v2.1.1.RELEASE, Spring v5.1.3.RELEASE
14/12/2018 09:09:55,448 INFO main testServerApplication:679 - The following profiles are active: prod
14/12/2018 09:10:02,101 ERROR main TomcatStarter:62 - Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'webSecurityConfiguration': Unsatisfied dependency expressed through method 'setContentNegotationStrategy' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcConfiguration': Unsatisfied dependency expressed through field 'tenantRestClient'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tenantRestClient': Unsatisfied dependency expressed through field 'restTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restTemplate' defined in class path resource [cloud/test/server/config/CustomConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.hateoas.config.ConverterRegisteringWebMvcConfigurer' available: expected single matching bean but found 2: org.springframework.hateoas.config.ConverterRegisteringWebMvcConfigurer#0,org.springframework.hateoas.config.ConverterRegisteringWebMvcConfigurer#1
14/12/2018 09:10:02,124 WARN main WebappClassLoaderBase:173 - The web application [ROOT] appears to have started a thread named [lettuce-eventExecutorLoop-1-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
io.netty.util.concurrent.SingleThreadEventExecutor.takeTask(SingleThreadEventExecutor.java:251)
io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:64)
io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
java.lang.Thread.run(Thread.java:748)
14/12/2018 09:10:02,128 WARN main AnnotationConfigServletWebServerApplicationContext:554 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
14/12/2018 09:10:02,163 ERROR main LoggingFailureAnalysisReporter:42 -
***************************
APPLICATION FAILED TO START
***************************
Description:
Field restTemplate in cloud.test.server.rest.clients.TenantRestClient required a single bean, but 2 were found:
- org.springframework.hateoas.config.ConverterRegisteringWebMvcConfigurer#0: defined in null
- org.springframework.hateoas.config.ConverterRegisteringWebMvcConfigurer#1: defined in null
Action:
Consider marking one of the beans as #Primary, updating the consumer to accept multiple beans, or using #Qualifier to identify the bean that should be consumed
Process finished with exit code 1
I tried to:
Set a #Qualifier on restTemplate in my #Configuration class
Remove the bean restTemplate in my #Configuration class
The first attempt did't change anything, with the latter I've this weir error:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field restTemplate in cloud.test.server.rest.clients.TenantRestClient required a bean of type 'org.springframework.web.client.RestTemplate' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your configuration.
Do you have any hint to solve this strange error? And...why does it happen just updating to Spring Boot >=2.0.4 (same code)?
Try annotation restTemplate bean with #Primary.
#Bean
#Primary
public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplateBuilder().setConnectTimeout(httpClientConnectionTimeout)
.setReadTimeout(httpClientReadTimeout).build();
ObjectMapper objectMapper = new ObjectMapper();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter(objectMapper));
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
return restTemplate;
}
please try with below property in the application.properties of your spring boot project. Then it will allow you to override the existing bean definitions with our custom with the same name.
spring.main.allow-bean-definition-overriding=true