当我试图使用Java bean映射器启动Spring Boot时,我得到了一个错误。我在Windows上使用Eclipse,Gradle构建。这只是我用来学习这些组件的一个学习项目。
我正在监听ActiveMQ Artemis队列,使用传入的数据调用web服务,然后将订单响应保存在MondodB中。除了映射器将api响应转换为MongoDB实体之外,所有组件都在工作。
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.5)
2021-04-30 14:16:15.860 INFO 2320 --- [ main] c.b.R.RestClientPocApplication : Starting RestClientPocApplication using Java 11.0.9 on PSPLT-F7VYYY2 with PID 2320 (C:\Users\Bwarrick\Workspaces\Java\RESTClientPOC\bin\main started by Bwarrick in C:\Users\Bwarrick\Workspaces\Java\RESTClientPOC)
2021-04-30 14:16:15.863 INFO 2320 --- [ main] c.b.R.RestClientPocApplication : No active profile set, falling back to default profiles: default
2021-04-30 14:16:16.405 INFO 2320 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2021-04-30 14:16:16.567 INFO 2320 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 157 ms. Found 1 MongoDB repository interfaces.
2021-04-30 14:16:16.991 INFO 2320 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[192.168.56.102:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
2021-04-30 14:16:17.064 INFO 2320 --- [68.56.102:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:49}] to 192.168.56.102:27017
2021-04-30 14:16:17.064 INFO 2320 --- [68.56.102:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:2, serverValue:50}] to 192.168.56.102:27017
2021-04-30 14:16:17.065 INFO 2320 --- [68.56.102:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=192.168.56.102:27017, type=STANDALONE, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=9, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=23420200}
2021-04-30 14:16:17.332 WARN 2320 --- [ main] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'artemisConsumer' defined in file [C:\Users\Bwarrick\Workspaces\Java\RESTClientPOC\bin\main\com\benwarrick\RESTClientPOC\jms\ArtemisConsumer.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.benwarrick.RESTClientPOC.service.OrderMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2021-04-30 14:16:17.355 INFO 2320 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-04-30 14:16:17.370 ERROR 2320 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 1 of constructor in com.benwarrick.RESTClientPOC.jms.ArtemisConsumer required a bean of type 'com.benwarrick.RESTClientPOC.service.OrderMapper' that could not be found.
Action:
Consider defining a bean of type 'com.benwarrick.RESTClientPOC.service.OrderMapper' in your configuration.
package com.benwarrick.RESTClientPOC.jms;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
import com.benwarrick.RESTClientPOC.persistance.OrderEntity;
import com.benwarrick.RESTClientPOC.persistance.OrderRepository;
import com.benwarrick.RESTClientPOC.service.CoinBaseClientServiceImpl;
import com.benwarrick.RESTClientPOC.service.OrderMapper;
import com.benwarrick.RESTClientPOC.service.OrderResponse;
import com.benwarrick.RESTClientPOC.service.Price;
import com.benwarrick.RESTClientPOC.service.Prices;
import reactor.core.publisher.Mono;
import reactor.core.publisher.Flux;
@Component
public class ArtemisConsumer {
private final OrderRepository orderRepository;
private final OrderMapper orderMapper;
@Autowired
public ArtemisConsumer(OrderRepository orderRepository, OrderMapper orderMapper) {
this.orderRepository = orderRepository;
this.orderMapper = orderMapper;
}
@JmsListener(destination = "test.topic::test.queue")
public void receive(String msg){
System.out.println("Got Message: " + msg);
CoinBaseClientServiceImpl client = new CoinBaseClientServiceImpl();
Mono<OrderResponse>orderCreate = client.createOrder("market", "USD", "BTC", "5");
orderCreate.log().subscribe(
successValue -> processResponse(successValue),
error -> System.err.println(error.getMessage()),
() -> System.out.println("mono consumed")
);
}
public void processResponse(OrderResponse orderResponse) {
System.out.println(orderResponse.getOrderID() + " " + orderResponse.getSellingCurrency() + orderResponse.getBuyingCurrency() + " Qty: "
+ orderResponse.getBoughtQty() + " Type: " + orderResponse.getOrderType()) ;
try {
OrderEntity entity = orderMapper.apiResponseToEntity(orderResponse);
OrderEntity newEntity = orderRepository.save(entity);
System.out.println("Test: " + newEntity.getBoughtQuantity());
}
catch(Exception e) {
System.out.println("Exception: " + e.toString()) ;
}
}
}
package com.benwarrick.RESTClientPOC;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;
@SpringBootApplication
@EnableAsync
public class RestClientPocApplication {
private static final Logger LOG = LoggerFactory.getLogger(RestClientPocApplication.class);
public static void main(String[] args) {
ConfigurableApplicationContext ctx =
SpringApplication.run(RestClientPocApplication.class, args);
String mongoDBHost = ctx.getEnvironment().getProperty("spring.data.mongodb.host");
String mongoDbPort = ctx.getEnvironment().getProperty("spring.data.mongodb.port");
LOG.info("Connected to MongoDb: " + mongoDBHost + ":" + mongoDbPort);
}
}
package com.benwarrick.RESTClientPOC.service;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import com.benwarrick.RESTClientPOC.persistance.OrderEntity;
@Mapper (componentModel = "spring")
public interface OrderMapper {
@Mappings({
@Mapping(target = "id", ignore = true),
@Mapping(target = "version", ignore = true),
@Mapping(target = "orderId", source="orderID"),
@Mapping(target = "orderID", source="boughtQty")
})
OrderEntity apiResponseToEntity(OrderResponse api);
}
和我的建筑。梯度
plugins {
id 'org.springframework.boot' version '2.4.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.benwarrick'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
ext {
mapstructVersion = "1.4.2.Final"
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-artemis'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
implementation("org.mapstruct:mapstruct:${mapstructVersion}")
compileOnly "org.mapstruct:mapstruct-processor:${mapstructVersion}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
implementation('org.springframework.boot:spring-boot-starter-data-mongodb')
testImplementation('de.flapdoodle.embed:de.flapdoodle.embed.mongo')
}
test {
useJUnitPlatform()
}
对于MapStruct,您需要正确地设置注释处理器,以便IDE(在您的例子中是Eclipse)和构建工具Gradle能够很好地协同工作。
您可以在MapStruct page uder IDE上阅读有关它的支持。现在我没办法让它在没有问题的情况下工作。
插件来拯救!现在,我建议您使用以下Gradle插件,该插件可以以适合您的方式设置Eclipse IDE。插件:https://plugins.gradle.org/plugin/com.diffplug.eclipse.apt
plugins {
...
id 'com.diffplug.eclipse.apt' version "3.29.1"
}
./gradlew eclipseJdtApt eclipseFactorypath eclipseJdt
我希望Eclipse Buildship能够接受这一点,并使它更容易支持他的特性。
问题内容: 我正在尝试使用此处描述的解决方案来解决烦人的“生命周期配置未涵盖的插件执行:org.codehaus.mojo:build-helper-maven-plugin:1.7:add-source(执行:默认,阶段:generate-源)”,当我将以下插件放在pom.xml上时: 但是当我运行mvn clean install时,我得到了: 原因:在存储库中找不到POM’org.eclip
我无法使用xml文件将查询结果映射到带有MyBatis和Spring Boot的bean。 但MyBatis似乎找不到xml映射器,因此无法在正确的bean上映射结果。我收到的错误是: 16:02:56,074错误[org.springframework.boot.web.servlet.support.errorpagefilter](默认任务-1)由于异常[找不到结果映射Mypackage.M
我有两种将实体映射到域的方法。 当我试图定义实体列表到域的映射方法时,我发现了用于映射集合元素的模糊映射方法。 有没有一种方法可以定义用于映射对象集合的方法
问题内容: 我有两个POJO,STOCK和STOCK_DETAILS(一对多关系)。我也有一个接口IAUDITLOG(具有两种方法)。我需要两个POJO都实现此接口,并想在这些方法中编写一些实现。但是,当我使用子类“ STOCKDETAILS”实现IAUDITLOG接口时,它将给出异常“您应具有setter属性” 股票分类: 库存明细类 IAUDITLOg界面: 堆栈跟踪: 任何人都可以让我知道吗
我定义了映射器,但Spring Boot无法检测到它。我好几天都找不到问题。请帮忙。尝试了IDEA和NetBeans。试图从这个线程添加一些关于main类的注释。 UserMapper.java 用户服务 UserController.java 主类