问题是关于在xml文件/中定义的骆驼路线中使用由mapstruct生成的Spring bean 我有以下配置: 春季java
### use for loop
myfun_stupid1 <- function(x){
ncols = dim(x)[2]
likelihood <- function(mu){
# I have to difine my function with the shape of input data!
# If I have a dataframe with 100 columnss, my hands will be broken...
# Can we do it automatically?
value = 0
for (col_num in 1:ncols)
value = value + sum((x[,col_num] - mu[col_num])^2)
return(value)
}
return(optim(par = rep(0,ncols),fn = likelihood,method = 'L-BFGS-B',
lower = rep(-20,ncols), upper = rep(20,ncols))$par)
}
myfun_stupid1(input_data_c2)
### use vectorlization
myfun_stupid2 <- function(x){
ncols = dim(x)[2]
x <- as.matrix(x)
likelihood <- function(mu){
# I have to difine my function with the shape of input data!
# If I have a dataframe with 100 columnss, my hands will be broken...
# Can we do it automatically?
x_minus = sweep(x, MARGIN = 2, mu)
# see sweep(x = matrix(1:12,6,2),MARGIN = 2,c(1,2)), matrix minus a vector
value <- sum(diag(t(x_minus) %*% x_minus))
return(value)
}
return(optim(par = rep(0,ncols),fn = likelihood,method = 'L-BFGS-B',
lower = rep(-20,ncols), upper = rep(20,ncols))$par)
}
myfun_stupid2(input_data_c2)
@Component
public class OrderMapperImpl implements OrderMapper {
@Override
public CreateOrderRequest map(Order value) {
}
}
骆驼xml路线
@Bean
public Jaxb2Marshaller jaxbUnmarshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("ru.sth.package");
return marshaller;
}
例外是
<?xml version="1.0" encoding="UTF-8"?>
<routes>
...
<route id="from_somewhere">
<from uri="{{random.endpoint}}"/>
<log message="Received message from ${body}"/>
<to uri="bean:jaxbUnmarshaller?method=unmarshal"/>
<to uri="bean:orderMapper?method=map"/>
<to uri="direct:toSomewhere" pattern="InOut"/>
</route>
...
</routes>
有趣的事情是,解组器一切正常。映射器也是由mapstruct生成的,并在编译时生成 有任何想法吗?
答案 0 :(得分:1)
Spring组件扫描将创建的bean是OrderMapperImpl
。在Spring中,默认情况下,带注释的Bean的名称是从类的简单名称生成的,首字母为小写。
因此,在您的情况下,bean的名称为orderMapperImpl,您应该在骆驼xml定义中使用它。