Как я могу решить эту проблему в моем приложении Crud? Это моя ошибка
***************************
APPLICATION FAILED TO START
***************************
Description:
Field repository in com.howtodoinjava.demo.service.UtentiServiceImpl required a bean named 'entityManagerFactory' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
Это мои классы
RepoConfig. java
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "modelEntityManagerFactory",
transactionManagerRef = "transactionManager",
basePackages = { "com.howtodoinjava.demo" }
)
@EnableAutoConfiguration
public class RepoConfig {
@Primary
@Bean(name = "modelDataSource")
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Primary
@Bean(name = "modelEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder
builder, @Qualifier("modelDataSource") DataSource dataSource) {
return builder
.dataSource(dataSource)
.packages(UtentiEntity.class)
.persistenceUnit("unipass")
.build();
}
@Primary
@Bean(name = "modelSessionFactory")
public SessionFactory sessionFactory(@Qualifier("modelDataSource") DataSource dataSource) {
LocalSessionFactoryBuilder localSessionFactoryBuilder = new
LocalSessionFactoryBuilder(dataSource);
return localSessionFactoryBuilder.buildSessionFactory();
}
@Primary
@Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager(
@Qualifier("modelEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
UtentiEntity. java
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(schema = "BASE", name = "TA11_UTENTI")
public class UtentiEntity {
@Id
@Column(name="cod_utente")
private String codUtente;
@Column(name="nome")
private String nome;
@Column(name="cognome")
private String cognome;
@Column(name="societa")
private String societa;
@Column(name="via")
private String via;
@Column(name="codice_postale")
private String codicePostale;
@Column(name="citta")
private String citta;
@Column(name="stato")
private String stato;
@Column(name="societa_tassa_id")
private String societaTassaId;
@Column(name="vat")
private String vat;
}
UtentiEntityRepository. java
@Repository
public interface UtentiEntityRepository extends JpaRepository<UtentiEntity, String> {
}
UtentiService. java
public interface UtentiService {
public UtentiEntity getUtentiEntityById(String id) throws RecordNotFoundException;
}
UtentiServiceImpl. java
@Service
public class UtentiServiceImpl implements UtentiService{
@Autowired
private UtentiEntityRepository repository;
@Override
public UtentiEntity getUtentiEntityById(String id) throws RecordNotFoundException
{
Optional<UtentiEntity> utentiEntity = repository.findById(id);
if(utentiEntity.isPresent()) {
return utentiEntity.get();
} else {
throw new RecordNotFoundException("No employee record exist for given id");
}
}
}
UtentiEntityController. java
@RestController
@RequestMapping("/utenti")
public class UtentiEntityController
{
@Autowired
UtentiServiceImpl service;
@GetMapping("/{id}")
public ResponseEntity<UtentiEntity> getUtentiEntityById(@PathVariable("id") String id)
throws RecordNotFoundException {
UtentiEntity entity = service.getUtentiEntityById(id);
return new ResponseEntity<UtentiEntity>(entity, new HttpHeaders(), HttpStatus.OK);
}
}
пом. xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.howtodoinjava</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.ibm.db2/jcc -->
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<version>11.1.4.4</version>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>