没有加载 MonetaryAmountsSingletonSpi
No MonetaryAmountsSingletonSpi loaded
在pom.xml中添加的依赖项:
<dependency>
<groupId>javax.money</groupId>
<artifactId>money-api</artifactId>
<version>1.0.3</version>
</dependency>
相关代码:
MonetaryAmount mon = Monetary.getDefaultAmountFactory()
//getCurrency() returns String
.setCurrency(amount.getCurrency())
//getContent() returns BigDecimal
.setNumber(amount.getContent())
.create();
单元测试时出现异常:
javax.money.MonetaryException: No MonetaryAmountsSingletonSpi loaded.
at javax.money.Monetary.lambda$getDefaultAmountFactory(Monetary.java:291)
JavaMoney 被拆分为 API 和实现的单独包,但您只将 API 添加到 POM。您还需要一个实现,例如参考实现:
<dependency>
<groupId>org.javamoney</groupId>
<artifactId>moneta</artifactId>
<version>1.2.1</version>
<type>pom</type>
</dependency>
在pom.xml中添加的依赖项:
<dependency>
<groupId>javax.money</groupId>
<artifactId>money-api</artifactId>
<version>1.0.3</version>
</dependency>
相关代码:
MonetaryAmount mon = Monetary.getDefaultAmountFactory()
//getCurrency() returns String
.setCurrency(amount.getCurrency())
//getContent() returns BigDecimal
.setNumber(amount.getContent())
.create();
单元测试时出现异常:
javax.money.MonetaryException: No MonetaryAmountsSingletonSpi loaded.
at javax.money.Monetary.lambda$getDefaultAmountFactory(Monetary.java:291)
JavaMoney 被拆分为 API 和实现的单独包,但您只将 API 添加到 POM。您还需要一个实现,例如参考实现:
<dependency>
<groupId>org.javamoney</groupId>
<artifactId>moneta</artifactId>
<version>1.2.1</version>
<type>pom</type>
</dependency>