admin管理员组文章数量:1403446
I am trying to migrate to GraalVM for Java-17 Springboot v3.4.1 based application. When I am running application with OpenJDK v17.0.14 , project is running fine. I am able to build with GraalVM, but on executing the build executable, it fails with not a managed type exception.
For GraalVM, I am using GraalVM Liberica-NIK-23.0.7-1 (build 17.0.14+10-LTS)
Stacktrace:
Caused by: .springframework.beans.factory.BeanCreationException: Error creating bean with name 'configLogRepository': Not a managed type: class com.project.demo.module.configLogs.domain.ConfigLog
at .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1808)
at .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601)
at .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523)
at .springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:336)
at .springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:289)
at .springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:334)
at .springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at .springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1573)
at .springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1519)
at .springframework.beans.factory.aot.AutowiredFieldValueResolver.resolveValue(AutowiredFieldValueResolver.java:186)
... 192 more
Caused by: java.lang.IllegalArgumentException: Not a managed type: class com.project.demo.module.configLogs.domain.ConfigLog
at .hibernate.metamodel.model.domain.internal.JpaMetamodelImpl.managedType(JpaMetamodelImpl.java:223)
at .hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.managedType(MappingMetamodelImpl.java:470)
at .hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.managedType(MappingMetamodelImpl.java:100)
at .springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:82)
at .springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:69)
at .springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:251)
at .springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:215)
at .springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:198)
at .springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:1)
at .springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:386)
at .springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$4(RepositoryFactoryBeanSupport.java:350)
at .springframework.data.util.Lazy.getNullable(Lazy.java:135)
at .springframework.data.util.Lazy.get(Lazy.java:113)
at .springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:356)
at .springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:132)
at .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
at .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804)
... 201 more
Complete Stacktrace:
My DatabaseConfiguration has single DataSource with configs as follows:
package com.project.demo.config;
import com.zaxxer.hikari.HikariDataSource;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import lombok.AllArgsConstructor;
import .springframework.beans.factory.annotation.Qualifier;
import .springframework.boot.context.properties.ConfigurationProperties;
import .springframework.boot.jdbc.DataSourceBuilder;
import .springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import .springframework.context.annotation.Bean;
import .springframework.context.annotation.Configuration;
import .springframework.context.annotation.Primary;
import .springframework.core.env.Environment;
import .springframework.data.jpa.repository.config.EnableJpaRepositories;
import .springframework.orm.jpa.JpaTransactionManager;
import .springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import .springframework.transaction.PlatformTransactionManager;
import .springframework.transaction.annotation.EnableTransactionManagement;
import .springframework.context.EnvironmentAware;
import jakarta.persistence.EntityManagerFactory;
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(entityManagerFactoryRef = "postgresEntityManagerFactory",
transactionManagerRef = "postgresTransactionManager",
basePackages = "com.project.demo")
@AllArgsConstructor
public class DatabaseConfiguration implements EnvironmentAware {
private Environment environment;
@Override
public void setEnvironment(Environment environment) {
this.environment = environment;
}
@Primary
@Bean(name = "postgresDataSource")
@ConfigurationProperties(prefix = "spring.datasource")
public HikariDataSource dataSource() {
return DataSourceBuilder.create().type(HikariDataSource.class)
.driverClassName(".postgresql.Driver")
.url("jdbc:postgresql://localhost:5432/demo")
.username(environment.getProperty("spring.datasource.username"))
.password(environment.getProperty("spring.datasource.password")).build();
}
public Map<String, String> hikariConfig() {
Map<String, String> properties = new HashMap<>();
properties.put("driverClassName", ".postgresql.Driver");
properties.put("url", "jdbc:postgresql://localhost:5432/demo");
properties.put("username", environment.getProperty("spring.datasource.username"));
properties.put("password", environment.getProperty("spring.datasource.password"));
properties.put("minimumIdle", "5"); properties.put("maximumPoolSize", "8");
properties.put("idleTimeout", "30000");
properties.put("poolName", "SpringBootJPAHikariCP");
properties.put("maxLifetime", "600000"); properties.put("keepaliveTime", "60000");
properties.put("connectionTimeout", "30000");
properties.put("initializationFailTimeout", "10000");
properties.put("minimumIdle", "10000");
return properties;
}
@Bean(name = "postgresTransactionManager")
public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
@Bean(name = "postgresEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder entityManagerFactoryBuilder, @Qualifier("postgresDataSource") DataSource dataSource) {
return entityManagerFactoryBuilder.dataSource(dataSource).packages("com.project.demo").properties(hikariConfig()).build();
}
}
ConfigLog Entity Class:
package com.project.demo.module.configLogs.domain;
import com.project.demo.module.masters.constants.OperationType;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDateTime;
@Entity
@Table(name = "config_log")
@Getter
@Setter
public class ConfigLog {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "user_id")
private Long userId;
@Column(name = "company_id")
private Long companyId;
@Column(name = "operation_type")
@Enumerated(value = EnumType.STRING)
private OperationType operationType;
@Column(name = "log_time")
private LocalDateTime logTime = LocalDateTime.now();
@Column(name = "json")
private String json;
@Override
public String toString() {
return "ConfigLog{" +
"id=" + id +
", userId=" + userId +
", companyId=" + companyId +
", operationType=" + operationType +
", logTime=" + logTime +
", json='" + json + '\'' +
'}';
}
}
Repository class:
package com.project.demo.module.configLogs.repository;
import com.project.demo.module.configLogs.domain.ConfigLog;
import .springframework.data.jpa.repository.JpaRepository;
import .springframework.stereotype.Repository;
@Repository
public interface ConfigLogRepository extends JpaRepository<ConfigLog, Long> {
}
Before creating question, I verified forllowing based on SO questions and github issues pages:
- I am using
jakarta.persistence
instead ofjavax.persistence
- Similar issue is reported for Projects with multiple DataSource, I verified that I am only using single DataSource
- I have
.hibernate.orm:hibernate-core:6.6.4.Final
and.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
in dependency tree.
pom.xml :
本文标签: javaGraalVM Spring Boot error with a repositoryentitynot a managed typeStack Overflow
版权声明:本文标题:java - GraalVM Spring Boot error with a repositoryentity, not a managed type - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744413077a2605054.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论