Code: Select all
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configLogRepository': Not a managed type: class com.project.demo.module.configLogs.domain.ConfigLog
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1808)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:336)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:289)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:334)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1573)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1519)
at org.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 org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl.managedType(JpaMetamodelImpl.java:223)
at org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.managedType(MappingMetamodelImpl.java:470)
at org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.managedType(MappingMetamodelImpl.java:100)
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.(JpaMetamodelEntityInformation.java:82)
at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:69)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:251)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:215)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:198)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:1)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:386)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$4(RepositoryFactoryBeanSupport.java:350)
at org.springframework.data.util.Lazy.getNullable(Lazy.java:135)
at org.springframework.data.util.Lazy.get(Lazy.java:113)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:356)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:132)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804)
... 201 more
Code: Select all
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 org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.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("org.postgresql.Driver")
.url("jdbc:postgresql://localhost:5432/demo")
.username(environment.getProperty("spring.datasource.username"))
.password(environment.getProperty("spring.datasource.password")).build();
}
public Map hikariConfig() {
Map properties = new HashMap();
properties.put("driverClassName", "org.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();
}
}
Code: Select all
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 + '\'' +
'}';
}
}
< /code>
Repository -Klasse: < /p>
package com.project.demo.module.configLogs.repository;
import com.project.demo.module.configLogs.domain.ConfigLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ConfigLogRepository extends JpaRepository {
}
[*] Ich verwende Jakarta.Persistenz anstelle von javax.persistence
[*] Ausgabe. DataSource
Ich habe org.hiNNATE.ORM: Hibernate-Core: 6.6.4.Final und org.hiNNate.javax.Persistenz: hibernate-jpa-2.1-api: 1.0.0.Final In Defency-Tree.>