我不确定为什么会遇到以下错误
#9 29.22 [ERROR] /src/main/java/com/nestwealth/ftpintegration/onboarding/response/OnboardingResponseRoute.java:[15,16] cannot find symbol
#9 29.22 [ERROR] symbol: class HmacGenerator
#9 29.22 [ERROR] location: class com.nestwealth.ftpintegration.onboarding.response.OnboardingResponseRoute
我声明了一个需要在多个位置使用的类,其定义如下
主机生成器.java
package com.example.ftpintegration;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.json.JSONObject;
@Component
public class HmacGenerator {
private String secretKey;
public HmacGenerator(@Value("{secret-key}") String secretKey){
this.secretKey = secretKey;
}
public String generateHmacKey (String sftpResponseObj){
log.warn("SFTP response: (" + sftpResponseObj);
String encodingType = "HmacSHA256";
JSONObject obj = new JSONObject(sftpResponseObj);
log.warn("Stringified SFTP response: (" + obj.toString());
return "test";
}
}
我尝试在以下类中使用上述方法generateHmacKey(...)
入站响应路由.java
package com.example.ftpintegration.onboarding.response;
import org.apache.camel.Exchange;
import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
import org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository;
import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Autowired;
@Component
public class OnboardingResponseRoute extends EndpointRouteBuilder {
private JdbcMessageIdRepository idempotentRepository;
@Autowired
public HmacGenerator hmacgenerator; //fails right here
public OnboardingResponseRoute(JdbcMessageIdRepository sftpOnboardingProcessor) {
this.idempotentRepository = sftpOnboardingProcessor;
}
@Override
public void configure() throws Exception {
from(sftp("{{sftp.host}}:{{sftp.port}}/{{sftp.path}}")
.username("{{sftp.user}}")
.password("{{sftp.password}}")
.recursive(false)
.useUserKnownHostsFile(false)
.delay("{{response.sftp.delay}}")
.delete(false)
.idempotent(true)
.idempotentRepository(idempotentRepository)
.advanced()
.stepwise(false)
.localWorkDirectory("{{sftp.tmp-directory}}"))
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
.setHeader("x-digest")
.method(hmacgenerator, "generateHmacKey(${body})")
.log("Started copying file: ${header.CamelFileName}")
.to("{{response.http.url}}/account-opening-response")
.log("Done copying file: ${header.CamelFileName}");
}
}
我的配置文件如下所示
聚合物.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 https://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.5.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.nestwealth</groupId>
<artifactId>ftpintegration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ftpintegration</name>
<description>SFTP to S3 Integration</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>3.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-bean-starter</artifactId>
<version>3.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-ftp-starter</artifactId>
<version>3.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-aws2-s3-starter</artifactId>
<version>3.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-http-starter</artifactId>
<version>3.11.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-55</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-jackson-starter</artifactId>
<version>3.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-jpa-starter</artifactId>
<version>3.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-sql-starter</artifactId>
<version>3.11.1</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-endpointdsl</artifactId>
<version>3.11.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20220924</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
1条答案
按热度按时间qyswt5oh1#
请检查你是否在你的主应用程序文件中添加了
@ComponentScan
并检查是否已将
HmacGenerator
导入OnboardingResponseRoute
: