JUnit is failing after upgrading to Spring boot 2.3 - java

Upgrading my Application from Spring boot 2.1.6 to Spring boot 2.3
After adding this property in my Yaml file, I am able to run my application
Spring.main.allow-bean-definition-overriding: true
But even after same property in my yml file , getting following error , any clue will be appreciated
java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException at DefaultListableBeanFactory.java:995
for reference this is my sample Junit class
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
#ActiveProfiles("local,test")
#DirtiesContext
public class ControllerContextTest {
}

Related

after upgrading the Spring boot version to 2.6, getting circular dependency error

Spring boot application failed to start after upgrading to 2.6.4 due to circular dependency.
I have two class like this:
class ABC{
#Autowired
PQR pqr;
}
Class PQR{
#Autowired
ABC abc;
}
previously working fine, now getting circular dependency error after upgrading spring boot to 2.6.4
How to resolve this?
You can write #Lazy annotation at top of one of the autowire . This will let your spring application compile without any error
Like below:
Class PQR{
#Lazy
#Autowired
ABC abc;
}

DAO test case getting failed

DAO test cases getting failed due to below error:
Caused by: java.lang.ClassNotFoundException: de.flapdoodle.embed.process.config.RuntimeConfig
we are using spring boot 2.7.3 version , Spring data mongoDB :3.4.2, MongoDB :4.2,
de.flaodoodle.embeded.mongo-2.2.0, de.flaodoodle.embeded.process-2.1.2
Please help for the same
Try adding this to your spring boot application:
#SpringBootApplication(exclude = EmbeddedMongoAutoConfiguration.class)
It will disable auto configuration as that causes issues. You can use your own configuration in this case.

#ComponentScan seens not to be working after migrate from Spring Boot 2.0 to 2.5

I have an application that was working in Spring Boot 1.5, than worked in 2.0.
Now I'm migrating to 2.5.7
This application uses a external lib. This lib also written using Spring Boot 2.5.7 and it users OpenFeign.
But now, when running, the main application seens not to be scanning the lib.
The error is:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field usersRestClient in my.library.package.infrastructure.acl.facade.user.UserFacade required a bean of type 'my.library.package.infrastructure.acl.restclient.user.UsersRestClient' that could not be found.
The injection point has the following annotations:
- #javax.inject.Inject()
Action:
Consider defining a bean of type 'my.library.package.acl.restclient.user.UsersRestClient' in your configuration.
I already tried to use ComponentScan at diferent places. I tried to Create a Configuration Class with ComponentScan at the lib and point in the main application using #Import.
Nothing worked.
I've edited the code leaving just whats matters.
In the lib:
The Service UserFacade uses the Component UsersRestClient
#Service
// I've already tried to put #ComponentScan here, didn't work.
public class UserFacade {
#Autowired
private UsersRestClient usersRestClient;
...
}
This is the component:
#RequestMapping("/users")
#Component("usersRestClient")
public interface UsersRestClient {
...
}
In the main App:
The main class
#SpringBootApplication
#ComponentScan(basePackages = {"my.library.package"})
#EnableAutoConfiguration
#EnableFeignClients({"my.library.package"})
public class ResourceAllocationServiceApplication {
...
}
Than, where I use the UseFacade Service:
#Component
public class RetrieveUserByIdUseCase {
#Autowired
private UserFacade userFacade;
...
}
Can anyone help? I found a similar issue here, but no answers worked.
#ComponentScan on external library not working

My actuators in spring boot are not working

I am trying to check whether my spring boot application is up and running via spring boot actuators. My spring boot application annotation contains this:
#SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class,
WebMvcAutoConfiguration.class,
HibernateJpaAutoConfiguration.class EntityManagerFactory
})
In my application properties file I have management.server.port=8081. But when I start up my application and try to run localhost:8081/actuator/info I got an error - This site can not be reached.
What am I doing wrong ?
Thank you for any help.

Spring boot project unable to resolve symbol SpringockitoContextLoader

I am getting error " cant resolve symbol SpringockitoContextLoader
" on this following line in test package
#ContextConfiguration(loader = SpringockitoContextLoader.class ....
I have migrated to spring 2.0.3 , I am suspecting SpringockitoContextLoader is not used anymore
Assuming you mean "Spring Boot" when you say "spring 2.0.3", you should use Spring Boot Test's built-in support for mocks and spies via #MockBean and #SpyBean instead of Springockito (which is a separate project that resides outside the official Spring portfolio).

Categories