org.springframework.boot.orm.jpa.EntityScan on Spring Boot 1.5.0-snapshot - spring-boot

The EntityScan class has removed from SpringBoot 1.5.0-SNAPSHOT,
When i change to 1.3.0-SNAPSHOT version, EntityScan exist.
i must add another dependancy to use EntityScan with SpringBoot 1.5.0-SNAPSHOT ?
https://github.com/spring-projects/spring-boot/issues/8231

Please read the release notes: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Release-Notes#entityscan :
The #org.springframework.boot.orm.jpa.EntityScan annotation has been
deprecated and should be replaced with
#org.springframework.boot.autoconfigure.domain.EntityScan or
explicit configuration.

Related

How to register ApplicationContextInitializer in Spring boot 2.7/3

I'm using Spring boot 2.7.7 and Spring boot 3.
I've already switched to the new way write my custom autoconfiguration class - that is with #AutoConfiguration and org.springframework.boot.autoconfigure.AutoConfiguration.imports inside META-INF/spring folder.
I want to add ApplicationContextInitializer. How do I do it the last spring boot versions (2.7.7 and 3)? I tried to add it to org.springframework.boot.autoconfigure.AutoConfiguration.imports file but initialize method is not being called.

Exclude Single Bean using #SpringBootApplication

I want to exclude a single Spring bean that's included in the packages scanned by Spring's component scan. I'd like to do this by using some kind of exclude parameter of the #SpringBootApplication annotation. All of Spring Boot's documentation seems to explain how to exclude "auto configuration classes" like LiquibaseAutoConfiguration.class. I don't want to exclude an auto configuration class - I'd just like to exclude a single bean. I'm using Spring Boot 2.7.4. Does anyone know how to do this?

Conflict with config class in dependency (Spring AsyncConfig)

My team uses some starter code that's included in every internal Spring project by default. This is included as a dependency (not parent) in the pom.xml file of my project. This starter code contains a default implementation of a configuration interface which Spring does not allow duplicates of (AsyncConfigurer), but I need to create my own custom implementation. I am not sure how to resolve this. Is there a way for me to exclude this configuration class but keep the rest of the dependency? Or can I somehow keep the given config class, but modify its properties?
The specific exception I get is: java.lang.IllegalStateException: Only one AsyncConfigurer may exist
//Thank you
You can define the AsyncConfigurer on parameter excludes from #SpringBootApplication. Example:
#SpringBootApplication(exclude=AsyncConfigurer.class)
Notice that this will excludes the entire #Configuration .
Another solution is to use bean override, to define only the beans you need to replace.
Add this to your application.properties (or yaml):
spring.main.allow-bean-definition-overriding=true
And you will be able to override it.

spring.jackson.default-property-inclusion=NON_NULL not working when added to application.yml file in spring boot 2.0

I am trying to add the jackson annotation at the application level via application.yml file. But when I run the application, the jackson annotation is ignored and the response has the null attributes as well. Cn someone help me here? I have added the below line in my application.yml
spring.jackson:
default-property-inclusion: NON_NULL
even after this I am seeing the response with null values.
Am I missing something or is there an issue with the version I m using? I am currently using jackson annotation version - 2.9.0
Property spring.jackson.default-property-inclusion: NON_NULL works with latest spring-boot version 2.5.0.
For older versions, where the property doesn't work, you can use #JsonInclude(Include.NON_NULL) annotation at class or field level.
Please note that field level annotation overrides the class level annotation, and class level annotation overrides the application level property.

Spring Boot JPA CrudRepository

I'm working with Spring Boot + Spring Data JPA and facing this problem when trying to inject a class that extends CrudRepository:
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'topicRepository': Could not resolve
matching constructor (hint: specify index/type/name arguments for
simple parameters to avoid type ambiguities)
Repository Class:
public interface TopicRepository extends CrudRepository<Topic, Integer> {}
Service Class:
#Service
public class TopicService {
#Autowired
private TopicRepository topicRepository;
}
Any suggestions?
I was having the same issue, and I fixed it by switching Spring Boot versions. Changing the Spring Data JPA versions did nothing (this is where I assumed the bug would be), so I think there is a bug in Spring Boot version 1.5.1. I switched back to version 1.4.3 and the error was gone. I didn't try subsequent/different versions, so you may just have to experiment with your dependencies and their versions.
For the record, you can have your service class annotated with #Repository, it shouldn't make any difference. I've been setting these apps up the same way using the service/dao pattern, and it has never been too picky with the annotations. Hopefully this may help others whose Spring Boot development flow suddenly throws an error!
Which versions of spring-data-commons and spring-data-jpa are you using. I just ran into this using spring-data-commons 1.13.x with spring-data-jpa 1.10.x. Upgrading spring-data-jpa to 1.11.x fixed the issue for me.
I too had the same issue after updating Spring Boot to 1.5.4.
I am also using spring-data-envers, which was at version 1.0.4. Upgrading to 1.4.1 solved the problem.
I hope it helps someone :)
Make sure:
1) TopicRepository is annotated with #Repository.
2) You have the scanning packages configured:
<jpa:repositories base-package="mypkg.repositories"></jpa:repositories>
Had the same issue on 1.5.2. Upgrading to 1.5.5 solved the problem.
You can use Applicationcontext to inject repository to this reference topicRepository..
You just declare applicationcontext in #rest controller class
Same like topicRepository by using annotation. Then you pass this to the service class which should take parms through constructor.
Ex-
public TopicService(Applicationcontext ctx) {this.topicRepository =context.getBean(TopicRepository.class);
}

Resources