Recently I have update my spring boot app from 1.5.6.Release to 2.3.5. While building project I am facing following problem :
Description:
A component required a bean named 'entityManagerFactory' that could not be found.
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
Following is my code:(@Repository and EnableJpaRepositories annotation are not required in spring boot)
@SpringBootApplication
@EnableScheduling
@ServletComponentScan
public class Application {
private static final Logger log = LoggerFactory.getLogger(Application.class);
public static void main(String[] args) {
for (String arg : args) {
}
SpringApplication.run(Application.class, args);
}
}
public interface EntityRepository extends JpaRepository<Entity, Integer> {
}
@RestController
public class PersonController {
private final EntityRepository entities;
@Autowired
public PersonController(EntityRepository wntities) {
this.etities = entities;
}
….
…..
}
> WARN 79448 --- [main] ConfigServletWebServerApplicationContext : > Exception encountered during context initialization - cancelling > refresh attempt: > org.springframework.beans.factory.BeanCreationException: Error > creating bean with name 'EntityRepository' defined in > com.abc.EntityRepository defined in @EnableJpaRepositories declared on > JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot > create inner bean '(inner bean)#6010d0d1' of type > [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting > bean property 'entityManager'; nested exception is > org.springframework.beans.factory.BeanCreationException: Error > creating bean with name '(inner bean)#6010d0d1': Cannot resolve > reference to bean 'entityManagerFactory' while setting constructor > argument; nested exception is > org.springframework.beans.factory.NoSuchBeanDefinitionException: No > bean named 'entityManagerFactory' available > INFO 79448 --- [main] o.s.s.c.ThreadPoolTaskScheduler : Shutting down ExecutorService 'taskScheduler' Description: A component required a bean named 'entityManagerFactory' that could not be found. Action: Consider defining a bean named 'entityManagerFactory' in your configuration.
Gradle Build file :
buildscript {
ext {
springBootVersion = ‘2.3.5’
}
repositories {
maven { url "https://artifactory.domain.com/mavenrepo" }
maven { url "https://artifactory.domain.com/maven.atlassian.com-cache" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.8”
}
}
apply plugin: "com.github.sherter.google-java-format"
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'findbugs'
apply plugin: 'maven-publish'
group = 'com.domain.xyz.myapp'
version = '1.0.1-SNAPSHOT'
repositories {
maven { url "https://artifactory.domain.com/mavenrepo" }
}
project.tasks.findAll { it.name.startsWith("publish") } .each { it.dependsOn assemble }
springBoot {
classifier = 'boot'
}
publishing {
publications {
maven(MavenPublication) {
artifact ("$buildDir/libs/$project.name-$version-boot.jar") {
classifier = 'boot'
}
}
}
repositories {
maven {
url "http://artifactory.xyz.com:8080/project-snapshots"
credentials {
username = "publish-username"
password = "publish-password"
}
}
}
}
tasks.withType(FindBugs) {
reports {
xml.enabled false
html.enabled true
}
}
configurations {
all*.exclude group: 'javax.servlet', module: 'servlet-api'
}
dependencies {
compileOnly('org.projectlombok:lombok:1.16.14')
compile('org.springframework.boot:spring-boot-starter-actuator')
annotationProcessor('org.projectlombok:lombok:1.18.8')
compile('org.springframework.boot:spring-boot-starter-cache')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-ldap')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-batch')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework:spring-web')
compile('com.google.guava:guava:r05')
runtime('mysql:mysql-connector-java:8.0.16')
runtime('org.hsqldb:hsqldb:2.3.3')
runtime('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('com.jayway.jsonpath:json-path')
compile('com.jcraft:jsch:0.1.53')
compile('net.sourceforge.jtds:jtds:1.3.1')
compile('jcifs:jcifs:1.3.17')
compile('org.apache.camel:camel-core:2.15.0')
compile('com.github.ulisesbocchio:jasypt-spring-boot-starter:2.1.1')
compile('io.micrometer:micrometer-spring-legacy:1.5.6')
}
Package Structure :
Project
src/main/java
src/main/resources
Application properties
build.gradle
gradlew
This is a gradle build system that I am using here.I have seen some similar questions where people deleted .m2 repository and solved it.For gradle I tried following command to re-download dependencies
./gradlew build --refresh-dependencies
but it did not solve my problem