【发布时间】:2017-07-03 12:37:51
【问题描述】:
我有 90% 使用服务和存储库访问的 POJO 类,但在这 10% 的情况下,我希望服务具有 POJO 的属性,在这些情况下自动装配失败。
在运行时,我得到“com.ripple.trading.impl.Trader 中构造函数的参数 0 需要一个无法找到的 'com.ripple.repositories.pojo.Wallet' 类型的 bean。”这是 Trader 类:
@Service
public class Trader implements ITrade {
private Wallet wallet;
private List<Quantity> balance;
private Advice latestAdvice;
@Autowired
private OrderService orderService;
@Autowired
private HistoryService historyService;
@Autowired
private CurrencyService currencyService;
private Advice lastAdvice;
public Trader(Wallet wallet, Advice advice){
this.lastAdvice = Advice.HOLD;
this.wallet = wallet;
this.balance = WalletFetcher.getWalletByAddress(this.wallet.getAddress());
this.latestAdvice = advice;
}
}
这是钱包
@Document
public class Wallet extends BaseModel implements Serializable{
private String address;
private String encryptedSecret;
private String name;
/**
* Instantiates a new Wallet.
*
* @param address the address
* @param encryptedSecret the encrypted secret
*/
@PersistenceConstructor
public Wallet(String address, String encryptedSecret, String name) {
this.address = address;
this.encryptedSecret = encryptedSecret;
this.name = name;
}
/**
* Gets address.
*
* @return the address
*/
public String getAddress() {
return address;
}
/**
* Sets address.
*
* @param address the address
*/
public void setAddress(String address) {
this.address = address;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
* Gets encrypted secret.
*
* @return the encrypted secret
*/
public String getEncryptedSecret() {
return encryptedSecret;
}
/**
* Sets encrypted secret.
*
* @param encryptedSecret the encrypted secret
*/
public void setEncryptedSecret(String encryptedSecret) {
this.encryptedSecret = encryptedSecret;
}
}
这是我的主要应用程序
@EnableOAuth2Sso
@ComponentScan
@EnableMongoRepositories(value = "com.ripple.repositories.mongo")
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
public class RippleSpringApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(RippleSpringApplication.class);
}
/**
* The entry point of application.
*
* @param args the input arguments
*/
public static void main(String[] args) {
SpringApplication.run(RippleSpringApplication.class, args);
}
}
我的猜测是自动装配,可能会将应用程序分解成更小的部分,直到它再次工作。这是以前发生过的问题,重构修复了它,但它背后的原因,为什么要修复它,是不是正确的解决方案。这就是我现在所追求的。
我的应用程序类在根包中,所以 ComponentScan 应该不是问题。
【问题讨论】:
标签: java spring spring-boot javabeans autowired