Spring context initialisation hangs when executing a test annotated with #SpringBootTest after a test annotated with #DataJpaTest - spring

I think I've stumbled about a bug in either Spring, Spring Boot, Spring Data JPA or Spring Data ReST. When I execute a test annotated with #DataJpaTest before a test annotated with #SpringBootTest the initialisation of the application context of the Spring Boot test hangs. Unfortunately the minimal example to reproduce the issue is too large to be posted here, so have uploaded an example project reproducing the issue here.
I have the following questions
Is it a bug or is it a strange setup?
Is the bug already known? (I have been looking for error problems in GitHub and StackOverflow, but found nothing that fits)
If it is a bug in which project Spring Framework, Spring Boot, Spring Data Jpa or Spring Data ReST should I open a bug issue?
Thanks for your help.

Related

How to prevent cucumber from hatching several SpringBoot context

I am using Cucumber + Spring Boot + Spring Cache
Every time Cucumber jumps from one Scenario Outline to the other, my Spring Boot context is rebuilt (I can see the Banner) and my Spring Cache is rebuild... which takes a lot of time.
I tried to add #DirtiesContext above the #SpringBootTest(Web) on the java steps class, that didn't helped.
How can I prevent Cucumber from refreshing the context on each and every Scenario?
Thanks
Upgrade your Cucumber to v5 and make sure you do not have #DirtiesContext any where in your spring configuration.
https://github.com/cucumber/cucumber-jvm/tree/master/spring

#DirtiesContext not working as expected after upgrading to Spring Boot 2.2.2

I am trying to upgrade my application from Spring Boot v2.1.8 to v2.2.2. However, after upgrading some tests start failing.
The pattern of failing tests strongly indicates that #DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD), applied on test class, is failing to clear context after each test case.
I am unable to narrow down further. Will appreciate any help.
I had the same issue today. With spring boot 2.2.7 not playing nice with Dirties context. In my case, I was using DBUnit to test and it wasn’t resetting the DB.
Adding this annotation fixed it for me:
#AutoConfigureTestDatabase(replace = Replace.ANY)

Not able to write Test cases for Spring Boot application with actual DB connection from Service to DAO

Can anyone let me know, how to write JUnit test cases for Spring Boot application with actual DB connection?
I mean to say, when we right click on #Test class in src/test/java, and click on Run as JUnit Test, we need to Autowire all the beans of Service and DAO which we had developed in src/main/java and control should flow from #Test class to Service and Service to DAO and queries should be executed using #PersistenceContext Entitymanager and return successfully with the desired results.
The stack specifications
Spring Boot 1.5.10
JPA
Please help me...
You can first refer to the documentation of the SpringBootTest
Spring Boot testing instruments allow you to 'slice' application into pieces, test it separately and test application as a whole. If you want to concentrate on database testing - consider using #DataJpaTest.
As for databases: it is a more common case to use in-memory databases like H2 during testing. But, if you want to test against the real databases, take a look at TestContainers or it's particular implementation (test container spring boot)

Intellij spring boot integration

For some reason Intellij 13.1.3 doesn't detect the spring boot beans. Spring boot version is 1.1.1-Release. When i try to inject ObjectMapper in some component i get an error in the IDE "No bean of type ObjectMapper defined", however the application compiles and runs just fine and the ObjectMapper beans is visible in the /beans json.
I have added my application-context and my Application.java files to a spring facet and the IDE recognizes all my other beans that I manually defined, it just ignores the ones that come with Spring boot #EnableAutoConfiguration. Any idea how to solve that since its kinda tedious not to have the correct linking in the IDE and get errors all over the place. I would assume thats a common issue?
Thanks!
As an update for this answer: IntelliJ now supports Spring Boot. Must be at least R14. R15 is including some more integration.
Spring Boot is not supported yet, please watch http://youtrack.jetbrains.com/issue/IDEA-119230

Basic interrogation about Spring boot and #EnableAutoConfiguration

I have a basic question about Spring Boot:
Say I am developping a websocket app. It seems the idea behind Spring Boot is as follows:
As a developer I am responsible for:
Including the following mvn dependency: spring-boot-starter-websocket
Annotate my configuration class with: #EnableAutoConfiguration
Spring Boot is then responsible for applying the following config: WebSocketAutoConfiguration
In a nutshell, is it how it works? Can someone please confirm of infirm the above?
You are absolutely correct.
After adding spring-boot-starter-websocket to your configuration file and using the #EnableAutoConfiguration annotation, Spring will use you class path to automatically determine which configuration settings and beans need to be created for you.
Spring Boot will handle the WebSocketAutoConfiguration and any other necessary common configurations.
More information can be found here: https://spring.io/guides/gs/spring-boot/

Resources