Я пытаюсь использовать Spring Boot и Vaadin в своем проекте. Он отлично работает в IntelliJ IDEA, но когда я собираю его как jar и запускаю с помощью java -jar, он выдает следующее исключение:
Microsoft Windows [Version 10.0.19045.4894]
(c) Microsoft Corporation. All rights reserved.
F:\myproj\vatest\out\artifacts\vatest_jar>java -jar vatest.jar fully.qualified.package.Application
21:51:34.320 [main] INFO ir.ic.vatest.VatestApplication -- Starting VatestApplication using Java 20.0.1 with PID 16832 (F:\myproj\vatest\out\artifacts\vatest_jar\vatest.jar started by S.NAZARI.H.P in F:\myproj\vatest\out\artifacts\vatest_jar)
21:51:34.324 [main] INFO ir.ic.vatest.VatestApplication -- No active profile set, falling back to 1 default profile: "default"
21:51:34.831 [main] WARN org.springframework.context.annotation.AnnotationConfigApplicationContext -- Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'formService': Unsatisfied dependency expressed through method 'setFormRepository' parameter 0: No qualifying bean of type 'ir.ic.vatest.db.FormRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
21:51:34.836 [main] ERROR org.springframework.boot.SpringApplication -- Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'formService': Unsatisfied dependency expressed through method 'setFormRepository' parameter 0: No qualifying bean of type 'ir.ic.vatest.db.FormRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.resolveMethodArguments(AutowiredAnnotationBeanPostProcessor.java:896)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:849)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:145)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:509)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1439)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:971)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:335)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352)
at ir.ic.vatest.VatestApplication.main(VatestApplication.java:10)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'ir.ic.vatest.db.FormRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1880)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1406)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1353)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.resolveMethodArguments(AutowiredAnnotationBeanPostProcessor.java:888)
мой класс сущности:
package ir.ic.vatest.db;
import jakarta.persistence.*;
@Entity
public class Forms {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@Column(name = "id")
private Integer id;
@Basic
@Column(name = "title")
private String title;
@Basic
@Column(name = "from_date")
private String fromDate;
@Basic
@Column(name = "to_date")
private String toDate;
@Basic
@Column(name = "active")
private Boolean active;
класс репозитория:
package ir.ic.vatest.db;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface FormRepository extends JpaRepository {
}
класс обслуживания:
package ir.ic.vatest.db;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class FormService {
@Autowired
private FormRepository formRepository;
public List findAll() {
return formRepository.findAll();
}
}
свойства приложения:
vaadin.launch-browser=true
spring.application.name=vatest
spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://localhost:3306/form
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql= true
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
класс приложения:
package ir.ic.vatest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class VatestApplication {
public static void main(String[] args) {
SpringApplication.run(VatestApplication.class, args);
}
}
класс пользовательского интерфейса
package ir.ic.vatest.view;
import com.vaadin.flow.component.Composite;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;
import ir.ic.vatest.db.FormService;
import ir.ic.vatest.db.Forms;
@Route(value = "home")
public class HomeView extends Composite {
private VerticalLayout mainVerticalLayout;
public HomeView(FormService formService) {
mainVerticalLayout = new VerticalLayout();
List formList = formService.findAll();
Grid grid = new Grid(Forms.class, false);
grid.addColumn(Forms::getTitle).setHeader("title");
grid.addColumn(Forms::getFromDate).setHeader("date");
grid.setItems(formList);
mainVerticalLayout.add(grid);
getContent().add(mainVerticalLayout);
}
}
pom.xml
4.0.0
org.springframework.boot
spring-boot-starter-parent
3.3.3
ir.ic
vaform
0.0.1-SNAPSHOT
vapro2
vapro2
17
24.4.9
org.springframework.boot
spring-boot-starter-data-jpa
com.vaadin
vaadin-spring-boot-starter
org.springframework.boot
spring-boot-devtools
true
org.springframework.boot
spring-boot-devtools
true
org.apache.poi
poi-ooxml
5.3.0
org.apache.derby
derby
org.apache.derby
derbytools
runtime
org.apache.derby
derbyclient
com.mysql
mysql-connector-j
runtime
org.springframework.boot
spring-boot-starter-test
test
jakarta.xml.bind
jakarta.xml.bind-api
4.0.0
com.sun.xml.bind
jaxb-impl
4.0.3
runtime
com.vaadin
vaadin-bom
${vaadin.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
production
com.vaadin
vaadin-core
com.vaadin
vaadin-dev
com.vaadin
vaadin-maven-plugin
${vaadin.version}
frontend
compile
prepare-frontend
build-frontend
Подробнее здесь: https://stackoverflow.com/questions/790 ... vice-class