#java #spring
Вопрос:
@Service
@AllArgsConstructor
@RequiredArgsConstructor
//@NoArgsConstructor
public class CurrencyExchange_Logic implements LogicInterface {
private final Currency_Interface currency_interface;
private final Rates_Interface rates_interface;
private final OldRates_Interface Oldrates_interface;
String start, end;
// methods
}
Трассировка стека:
C:Usersmtsge.jdksazul-13.0.6binjava.exe "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2019.3.4libidea_rt.jar=60750:C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2019.3.4bin" -Dfile.encoding=UTF-8 -classpath "C:UsersmtsgeOneDrivePulpitSyfCurrency Exchange2currence_exchangetargetclasses;C:Usersmtsge.m2repositoryorgspringframeworkbootspring-boot-starter-data-jdbc2.6.0spring-boot-starter-data-jdbc-2.6.0.jar;C:Usersmtsge.m2repositoryorgspringframeworkbootspring-boot-starter-jdbc2.6.0spring-boot-starter-jdbc-2.6.0.jar;C:Usersmtsge.m2repositorycomzaxxerHikariCP4.0.3HikariCP-4.0.3.jar;C:Usersmtsge.m2repositoryorgspringframeworkspring-jdbc5.3.13spring-jdbc-5.3.13.jar;C:Usersmtsge.m2repositoryorgspringframeworkdataspring-data-jdbc2.3.0spring-data-jdbc-2.3.0.jar;C:Usersmtsge.m2repositoryorgspringframeworkdataspring-data-relational2.3.0spring-data-relational-2.3.0.jar;C:Usersmtsge.m2repositoryorgspringframeworkdataspring-data-commons2.6.0spring-data-commons-2.6.0.jar;C:Usersmtsge.m2repositoryorgspringframeworkspring-tx5.3.13spring-tx-5.3.13.jar;C:Usersmtsge.m2repositoryorgspringframeworkbootspring-boot-starter-data-jpa2.6.0spring-boot-starter-data-jpa-2.6.0.jar;C:Usersmtsge.m2repositoryjakartatransactionjakarta.transaction-api1.3.3jakarta.transaction-api-1.3.3.jar;C:Usersmtsge.m2repositoryjakartapersistencejakarta.persistence-api2.2.3jakarta.persistence-api-2.2.3.jar;C:Usersmtsge.m2repositoryorghibernatehibernate-core5.6.1.Finalhibernate-core-5.6.1.Final.jar;C:Usersmtsge.m2repositoryorgjbossloggingjboss-logging3.4.2.Finaljboss-logging-3.4.2.Final.jar;C:Usersmtsge.m2repositoryantlrantlr2.7.7antlr-2.7.7.jar;C:Usersmtsge.m2repositoryorgjbossjandex2.2.3.Finaljandex-2.2.3.Final.jar;C:Usersmtsge.m2repositorycomfasterxmlclassmate1.5.1classmate-1.5.1.jar;C:Usersmtsge.m2repositoryorghibernatecommonhibernate-commons-annotations5.1.2.Finalhibernate-commons-annotations-5.1.2.Final.jar;C:Usersmtsge.m2repositoryorgglassfishjaxbjaxb-runtime2.3.5jaxb-runtime-2.3.5.jar;C:Usersmtsge.m2repositoryorgglassfishjaxbtxw22.3.5txw2-2.3.5.jar;C:Usersmtsge.m2repositorycomsunistackistack-commons-runtime3.0.12istack-commons-runtime-3.0.12.jar;C:Usersmtsge.m2repositorycomsunactivationjakarta.activation1.2.2jakarta.activation-1.2.2.jar;C:Usersmtsge.m2repositoryorgspringframeworkdataspring-data-jpa2.6.0spring-data-jpa-2.6.0.jar;C:Usersmtsge.m2repositoryorgspringframeworkspring-orm5.3.13spring-orm-5.3.13.jar;C:Usersmtsge.m2repositoryorgspringframeworkspring-aspects5.3.13spring-aspects-5.3.13.jar;C:Usersmtsge.m2repositoryorgspringframeworkbootspring-boot-starter-thymeleaf2.6.0spring-boot-starter-thymeleaf-2.6.0.jar;C:Usersmtsge.m2repositoryorgspringframeworkbootspring-boot-starter2.6.0spring-boot-starter-2.6.0.jar;C:Usersmtsge.m2repositoryorgspringframeworkbootspring-boot2.6.0spring-boot-2.6.0.jar;C:Usersmtsge.m2repositoryorgspringframeworkbootspring-boot-autoconfigure2.6.0spring-boot-autoconfigure-2.6.0.jar;C:Usersmtsge.m2repositoryorgspringframeworkbootspring-boot-starter-logging2.6.0spring-boot-starter-logging-2.6.0.jar;C:Usersmtsge.m2repositorychqoslogbacklogback-classic1.2.7logback-classic-1.2.7.jar;C:Usersmtsge.m2repositorychqoslogbacklogback-core1.2.7logback-core-1.2.7.jar;C:Usersmtsge.m2repositoryorgapachelogginglog4jlog4j-to-slf4j2.14.1log4j-to-slf4j-2.14.1.jar;C:Usersmtsge.m2repositoryorgapachelogginglog4jlog4j-api2.14.1log4j-api-2.14.1.jar;C:Usersmtsge.m2repositoryorgslf4jjul-to-slf4j1.7.32jul-to-slf4j-1.7.32.jar;C:Usersmtsge.m2repositoryjakartaannotationjakarta.annotation-api1.3.5jakarta.annotation-api-1.3.5.jar;C:Usersmtsge.m2repositoryorgyamlsnakeyaml1.29snakeyaml-1.29.jar;C:Usersmtsge.m2repositoryorgthymeleafextrasthymeleaf-extras-java8time3.0.4.RELEASEthymeleaf-extras-java8time-3.0.4.RELEASE.jar;C:Usersmtsge.m2repositoryorgspringframeworkbootspring-boot-starter-validation2.6.0spring-boot-starter-validation-2.6.0.jar;C:Usersmtsge.m2repositoryorgapachetomcatembedtomcat-embed-el9.0.55tomcat-embed-el-9.0.55.jar;C:Usersmtsge.m2repositoryorghibernatevalidatorhibernate-validator6.2.0.Finalhibernate-validator-6.2.0.Final.jar;C:Usersmtsge.m2repositoryjakartavalidationjakarta.validation-api2.0.2jakarta.validation-api-2.0.2.jar;C:Usersmtsge.m2repositoryorgspringframeworkbootspring-boot-starter-web2.6.0spring-boot-starter-web-2.6.0.jar;C:Usersmtsge.m2repositoryorgspringframeworkbootspring-boot-starter-json2.6.0spring-boot-starter-json-2.6.0.jar;C:Usersmtsge.m2repositorycomfasterxmljacksondatatypejackson-datatype-jdk82.13.0jackson-datatype-jdk8-2.13.0.jar;C:Usersmtsge.m2repositorycomfasterxmljacksondatatypejackson-datatype-jsr3102.13.0jackson-datatype-jsr310-2.13.0.jar;C:Usersmtsge.m2repositorycomfasterxmljacksonmodulejackson-module-parameter-names2.13.0jackson-module-parameter-names-2.13.0.jar;C:Usersmtsge.m2repositoryorgspringframeworkbootspring-boot-starter-tomcat2.6.0spring-boot-starter-tomcat-2.6.0.jar;C:Usersmtsge.m2repositoryorgapachetomcatembedtomcat-embed-core9.0.55tomcat-embed-core-9.0.55.jar;C:Usersmtsge.m2repositoryorgapachetomcatembedtomcat-embed-websocket9.0.55tomcat-embed-websocket-9.0.55.jar;C:Usersmtsge.m2repositoryorgspringframeworkspring-web5.3.13spring-web-5.3.13.jar;C:Usersmtsge.m2repositorymysqlmysql-connector-java8.0.27mysql-connector-java-8.0.27.jar;C:Usersmtsge.m2repositoryjavaxmoneymoney-api1.0.1money-api-1.0.1.jar;C:Usersmtsge.m2repositoryorgjavamoneymoneta1.0moneta-1.0.jar;C:Usersmtsge.m2repositoryjavaxannotationjavax.annotation-api1.3.2javax.annotation-api-1.3.2.jar;C:Usersmtsge.m2repositoryorgthymeleafthymeleaf3.0.11.RELEASEthymeleaf-3.0.11.RELEASE.jar;C:Usersmtsge.m2repositoryognlognl3.1.12ognl-3.1.12.jar;C:Usersmtsge.m2repositoryorgjavassistjavassist3.20.0-GAjavassist-3.20.0-GA.jar;C:Usersmtsge.m2repositoryorgattoparserattoparser2.0.5.RELEASEattoparser-2.0.5.RELEASE.jar;C:Usersmtsge.m2repositoryorgunbescapeunbescape1.1.6.RELEASEunbescape-1.1.6.RELEASE.jar;C:Usersmtsge.m2repositoryorgslf4jslf4j-api1.7.32slf4j-api-1.7.32.jar;C:Usersmtsge.m2repositoryorgspringframeworkspring-webmvc5.3.7spring-webmvc-5.3.7.jar;C:Usersmtsge.m2repositoryorgspringframeworkspring-aop5.3.13spring-aop-5.3.13.jar;C:Usersmtsge.m2repositoryorgspringframeworkspring-beans5.3.13spring-beans-5.3.13.jar;C:Usersmtsge.m2repositoryorgspringframeworkspring-context5.3.13spring-context-5.3.13.jar;C:Usersmtsge.m2repositoryorgspringframeworkspring-core5.3.13spring-core-5.3.13.jar;C:Usersmtsge.m2repositoryorgspringframeworkspring-jcl5.3.13spring-jcl-5.3.13.jar;C:Usersmtsge.m2repositoryorgspringframeworkspring-expression5.3.13spring-expression-5.3.13.jar;C:Usersmtsge.m2repositoryorgspringframeworkbootspring-boot-starter-aop2.5.2spring-boot-starter-aop-2.5.2.jar;C:Usersmtsge.m2repositoryorgaspectjaspectjweaver1.9.7aspectjweaver-1.9.7.jar;C:Usersmtsge.m2repositoryorgthymeleafthymeleaf-spring53.0.11.RELEASEthymeleaf-spring5-3.0.11.RELEASE.jar;C:Usersmtsge.m2repositorycomgooglecodegsongson2.8.5gson-2.8.5.jar;C:Usersmtsge.m2repositorycommicrosoftsqlservermssql-jdbc9.4.0.jre8mssql-jdbc-9.4.0.jre8.jar;C:Usersmtsge.m2repositoryorgprojectlomboklombok1.18.22lombok-1.18.22.jar;C:Usersmtsge.m2repositoryjakartaxmlbindjakarta.xml.bind-api2.3.3jakarta.xml.bind-api-2.3.3.jar;C:Usersmtsge.m2repositoryjakartaactivationjakarta.activation-api1.2.2jakarta.activation-api-1.2.2.jar;C:Usersmtsge.m2repositorynetbytebuddybyte-buddy1.11.22byte-buddy-1.11.22.jar;C:Usersmtsge.m2repositorycomfasterxmljacksoncorejackson-databind2.11.3jackson-databind-2.11.3.jar;C:Usersmtsge.m2repositorycomfasterxmljacksoncorejackson-annotations2.13.0jackson-annotations-2.13.0.jar;C:Usersmtsge.m2repositorycomfasterxmljacksoncorejackson-core2.13.0jackson-core-2.13.0.jar" com.example.currence_exchange.CurrenceExchangeApplication
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _
( ( )___ | '_ | '_| | '_ / _` |
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.0)
2021-11-28 23:09:44.805 INFO 6976 --- [ main] c.e.c.CurrenceExchangeApplication : Starting CurrenceExchangeApplication using Java 13.0.6 on DESKTOP-61G00PJ with PID 6976 (C:UsersmtsgeOneDrivePulpitSyfCurrency Exchange2currence_exchangetargetclasses started by mtsge in C:UsersmtsgeOneDrivePulpitSyfCurrency Exchange2)
2021-11-28 23:09:44.810 INFO 6976 --- [ main] c.e.c.CurrenceExchangeApplication : No active profile set, falling back to default profiles: default
2021-11-28 23:09:46.741 INFO 6976 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2021-11-28 23:09:46.741 INFO 6976 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-11-28 23:09:46.855 INFO 6976 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 93 ms. Found 3 JPA repository interfaces.
2021-11-28 23:09:47.146 INFO 6976 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2021-11-28 23:09:47.147 INFO 6976 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JDBC repositories in DEFAULT mode.
2021-11-28 23:09:47.162 INFO 6976 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data JDBC - Could not safely identify store assignment for repository candidate interface com.example.currence_exchange.Interfaces.Currency_Interface. If you want this repository to be a JDBC repository, consider annotating your entities with one of these annotations: org.springframework.data.relational.core.mapping.Table.
2021-11-28 23:09:47.163 INFO 6976 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data JDBC - Could not safely identify store assignment for repository candidate interface com.example.currence_exchange.Interfaces.OldRates_Interface. If you want this repository to be a JDBC repository, consider annotating your entities with one of these annotations: org.springframework.data.relational.core.mapping.Table.
2021-11-28 23:09:47.165 INFO 6976 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data JDBC - Could not safely identify store assignment for repository candidate interface com.example.currence_exchange.Interfaces.Rates_Interface. If you want this repository to be a JDBC repository, consider annotating your entities with one of these annotations: org.springframework.data.relational.core.mapping.Table.
2021-11-28 23:09:47.166 INFO 6976 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 17 ms. Found 0 JDBC repository interfaces.
2021-11-28 23:09:48.606 INFO 6976 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-11-28 23:09:48.624 INFO 6976 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-11-28 23:09:48.624 INFO 6976 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.55]
2021-11-28 23:09:48.844 INFO 6976 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-11-28 23:09:48.845 INFO 6976 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3880 ms
2021-11-28 23:09:49.138 INFO 6976 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-11-28 23:09:49.228 INFO 6976 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.1.Final
2021-11-28 23:09:49.507 INFO 6976 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-11-28 23:09:49.704 INFO 6976 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-11-28 23:09:50.381 INFO 6976 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-11-28 23:09:50.429 INFO 6976 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2021-11-28 23:09:51.771 INFO 6976 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-11-28 23:09:51.789 INFO 6976 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-11-28 23:09:51.810 WARN 6976 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'viewControllers' defined in file [C:UsersmtsgeOneDrivePulpitSyfCurrency Exchange2currence_exchangetargetclassescomexamplecurrence_exchangeControllersViewControllers.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'currencyExchange_Logic' defined in file [C:UsersmtsgeOneDrivePulpitSyfCurrency Exchange2currence_exchangetargetclassescomexamplecurrence_exchangeServiceCurrencyExchange_Logic.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.currence_exchange.Service.CurrencyExchange_Logic]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.example.currence_exchange.Service.CurrencyExchange_Logic.<init>()
2021-11-28 23:09:51.811 INFO 6976 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2021-11-28 23:09:51.815 INFO 6976 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2021-11-28 23:09:51.841 INFO 6976 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2021-11-28 23:09:51.843 INFO 6976 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-11-28 23:09:51.860 INFO 6976 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-11-28 23:09:51.893 ERROR 6976 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'viewControllers' defined in file [C:UsersmtsgeOneDrivePulpitSyfCurrency Exchange2currence_exchangetargetclassescomexamplecurrence_exchangeControllersViewControllers.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'currencyExchange_Logic' defined in file [C:UsersmtsgeOneDrivePulpitSyfCurrency Exchange2currence_exchangetargetclassescomexamplecurrence_exchangeServiceCurrencyExchange_Logic.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.currence_exchange.Service.CurrencyExchange_Logic]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.example.currence_exchange.Service.CurrencyExchange_Logic.<init>()
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.13.jar:5.3.13]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.13.jar:5.3.13]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.0.jar:2.6.0]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[spring-boot-2.6.0.jar:2.6.0]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) ~[spring-boot-2.6.0.jar:2.6.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.0.jar:2.6.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.0.jar:2.6.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[spring-boot-2.6.0.jar:2.6.0]
at com.example.currence_exchange.CurrenceExchangeApplication.main(CurrenceExchangeApplication.java:14) ~[classes/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'currencyExchange_Logic' defined in file [C:UsersmtsgeOneDrivePulpitSyfCurrency Exchange2currence_exchangetargetclassescomexamplecurrence_exchangeServiceCurrencyExchange_Logic.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.currence_exchange.Service.CurrencyExchange_Logic]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.example.currence_exchange.Service.CurrencyExchange_Logic.<init>()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1334) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1232) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.13.jar:5.3.13]
... 19 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.currence_exchange.Service.CurrencyExchange_Logic]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.example.currence_exchange.Service.CurrencyExchange_Logic.<init>()
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1326) ~[spring-beans-5.3.13.jar:5.3.13]
... 31 common frames omitted
Caused by: java.lang.NoSuchMethodException: com.example.currence_exchange.Service.CurrencyExchange_Logic.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3350) ~[na:na]
at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2554) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78) ~[spring-beans-5.3.13.jar:5.3.13]
... 32 common frames omitted
Process finished with exit code 1
Класс контроллера
@Controller
@RequiredArgsConstructor
public class ViewControllers {
private final CurrencyExchange_Logic currencyExchange_logic;
private final Rates_Interface rates_interface;
private final OldRates_Interface Oldrates_interface;
@PostMapping("specificRate")
public String getSpecificRate(Model model, @ModelAttribute("specific") @Valid RatesViewModel ratesViewModel) {
Set set = new HashSet<>();
set.add(rates_interface.getByCode(ratesViewModel.getCode()));
set.add(Oldrates_interface.getByCode(ratesViewModel.getCode()));
model.addAttribute("spec", set);
return "formPage";
}
@GetMapping("all")
public String all(Model model, @RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "size", defaultValue = "5") Integer size) {
Page<CurrencyEntity> ratePage = currencyExchange_logic.pagination(PageRequest.of(page - 1, size));
model.addAttribute("all", ratePage);
int totalPages = ratePage.getTotalPages();
if (totalPages > 0) {
List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages)
.boxed()
.collect(Collectors.toList());
model.addAttribute("pageNumbers", pageNumbers);
}
return "allPage";
}
@GetMapping("AllRates")
public String allRates(Model model) {
model.addAttribute("ratesOf", new DatesViewModel());
model.addAttribute("allRates", rates_interface.findAll());
return "allRates";
}
@GetMapping("/")
public String mainPaige(Model model) {
model.addAttribute("currencyAndAmount", new CurrencyViewModel());
return "formPage";
}
@PostMapping("RatesOfPeriod")
public String RatesOfPeriod(@ModelAttribute("ratesOf") @Valid DatesViewModel datesViewModel,
BindingResult bindingResult, Model model) {
if (!bindingResult.hasErrors()) {
String start = Objects.toString(datesViewModel.getDatesFrom(), "");
String end = Objects.toString(datesViewModel.getDatesTo(), "");
try {
currencyExchange_logic.getRatesOfDates(start, end);
model.addAttribute("allRates", Oldrates_interface.findAll());
Oldrates_interface.deleteAll();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
return "allRates";
}
@PostMapping("Calculate")
public String Calculate(@ModelAttribute("currencyAndAmount") @Valid CurrencyViewModel currencyViewModel,
BindingResult bindingResult, Model model) {
if (!bindingResult.hasErrors()) {
var entity = currencyExchange_logic.CurrencyViewModelToEntity(currencyViewModel);
String start = Objects.toString(entity.getDateFrom(), "");
String end = Objects.toString(entity.getDateTo(), "");
try {
MonetaryAmountJson currencyJson = currencyExchange_logic.currencyJson(start, end);
var calVal = currencyExchange_logic.calculateMoney(currencyJson, entity);
model.addAttribute("endValue", calVal);
} catch (IOException e) {
System.out.println(e.getMessage());
}
return "end";
} else {
return "formPage";
}
}
// TODO: 28.11.2021 napisac testy i ZREFAKTOROWAC
}
интерфейсы
Repository
public interface Rates_Interface extends JpaRepository<RatesEntity, Long> {
@Query("select r from RatesEntity r where r.code = :code")
List<RatesEntity> getByCode(@Param("code") CurrencyEnum code);
}
@Repository
public interface OldRates_Interface extends JpaRepository<OldRatesEntity, Long> {
@Query("select r from OldRatesEntity r where r.code = :code")
List<OldRatesEntity> getByCode(@Param("code") CurrencyEnum code);
}
Вопрос, который у меня есть, заключается в том, что стек сообщает, что бобовый Currency_Interface_Logic не может быть создан, потому что у вышеприведенного класса нет конструктора по умолчанию и, следовательно, он не может вводить зависимости, но аннотировал этот класс @AllArgsConstructor
@RequiredArgsConstructor
(может добавить @NoArgsConstructor
), так что все должно быть в порядке. Почему я получаю эту ошибку и как ее исправить?
Все было хорошо, пока я не добавил новый @PostMapping
метод ( getSpecificRate()
) и новые методы запросов в вышеуказанных интерфейсах
Комментарии:
1. Что вы подразумеваете под «не могу добавить @NoArgsConstructor»?
2. @TylerLiu Я думаю, это потому, что необходимо создать экземпляр конечных полей, и ломбок не может угадать, с какими значениями.
3. @TylerLiu, как сказал пэр
4. @peer но даже без ломбока я не могу добавить конструктор параметров, потому что я получаю: Переменная «rates_interface», возможно, не была инициализирована и т. Д.
5. Не уверен, что это напрямую решит вашу проблему, но вы должны использовать
@RestController
аннотацию в своем классе контроллера, чтобы@ResponseBody
она была включена.
Ответ №1:
В вашем CurrencyExchange_Logic
классе есть два конструктора: требуемый конструктор args, у которого есть параметры, соответствующие 3 final
полям, и конструктор all args с параметрами, соответствующими этим 3 полям, а также start
и end
.
Когда у вас определен только один конструктор, Spring знает, как неявно выбрать его для инъекции. Однако, если у вас их несколько, вы должны указать, какой из них вы хотите использовать, используя @Autowired
@Inject
аннотацию или.
Я бы предположил, что вы хотите, чтобы Spring использовал необходимый конструктор args, так как я сомневаюсь, что Spring знает, как разрешить поля start
или end
. Это можно сделать в lombok ( @RequiredArgsConstructor(onConstructor_ = @Autowired)
) или просто явно написав конструктор самостоятельно и аннотировав его. Обратите внимание, что вы также можете избавиться от конструктора all args, если он вам не нужен, и неявная инъекция конструктора Spring должна «просто работать».
Комментарии:
1. Я удалил AllArgsConstructor, и это сработало, большое спасибо!