Весенний ботинок. Ошибка начала приложенияJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Весенний ботинок. Ошибка начала приложения

Сообщение Anonymous »

Я столкнулся со следующей ошибкой во время запуска моего приложения Spring Boot: < /p>
Error starting ApplicationContext.

org.springframework.beans.factory.UnsatisfiedDependencyException:Error creating bean with name 'feedController'
Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'productService'
Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'productRepository' defined in team.capybara.backend.spring.controllers.repositories.ProductRepository defined in @EnableJpaRepositories declared on Main: Cannot resolve reference to bean 'jpaSharedEM_entityManagerFactory' while setting bean property 'entityManager'
< /code>
Я прочитал много статей и нашел информацию, которую я должен вручную настроить 'EntityManagerFactory', и это помогло мне с моей первоначальной проблемой: < /p>
Error starting ApplicationContext.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: jakarta/persistence/PersistenceUnitTransactionType
< /code>
Но я должен сказать, что мои классы организации написаны неправильно. По -видимому, есть проблемы в OneTomany и других связях.@Entity
@Table(name="Products")
public class Product {

@Id
@Column(name="id", nullable = false, unique = true)
private String id;

@OneToOne
@JoinColumn(name = "product_type_id")
private ProductType productType;

@Column(name="shelf_life", nullable = false)
private Date shelfLife; //last day of life

@Column(name="price", nullable = false)
private int price; // final price of product

@Column(name="discount", nullable = false)
private int discount; // discount amount in monetary units

@Column(name="is_sold", nullable = false)
private int isSold; //0 - false; 1 - true

public Product() {

}

public Product(ProductType productType,Date shelfLife,int price,int discount,int isSold){
this.id = (UUID.randomUUID()).toString();
this.productType = productType;
this.shelfLife = shelfLife;
this.price = price;
this.discount = discount;
this.isSold = isSold;
}
< /code>
pom.xml:


4.0.0

org.springframework.boot
spring-boot-starter-parent
3.5.6


team.capybara
vSrok
0.0.1-SNAPSHOT
vSrok

25



org.springframework.boot
spring-boot-autoconfigure


org.springframework.boot
spring-boot-starter-data-jpa


org.springframework.boot
spring-boot-starter-web



org.postgresql
postgresql
runtime


org.springframework.boot
spring-boot-starter-test
test



org.hibernate.orm
hibernate-core
7.1.1.Final


com.google.guava
guava
33.5.0-jre


junit
junit
4.13.2
test






org.springframework.boot
spring-boot-maven-plugin





< /code>
Основной класс: < /p>
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan(basePackages = {"team.capybara.backend.spring"})
@EntityScan(basePackages = {"team.capybara.backend.hibernate"})
@EnableJpaRepositories(basePackages = {"team.capybara.backend.spring.controllers.repositories"})
public class Main {
static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
< /code>
Класс конфигурации, который помог мне сделать Advance < /p>
@Configuration
public class AppConfig {
@Bean(name="entityManagerFactory")
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();

return sessionFactory;
}
}
< /code>
Just Repository: < /p>
@Repository
public interface ProductRepository extends JpaRepository {
}


Подробнее здесь: https://stackoverflow.com/questions/797 ... ioncontext
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»