Я столкнулся со следующей ошибкой во время запуска моего приложения 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
Весенний ботинок. Ошибка начала приложения ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1759597362
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 {
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79782578/spring-boot-error-starting-applicationcontext[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия