Java AOPINotificationException:在JUnit中的@Autowieired中
在我的java spring mvc应用程序中,我使用以下代码: 存储库:Java AOPINotificationException:在JUnit中的@Autowieired中,java,spring,junit,Java,Spring,Junit,在我的java spring mvc应用程序中,我使用以下代码: 存储库: @Repository public interface TransactionRepository extends JpaRepository<Transactions ,Long >{ @Query(value = "SELECT sum( value) FROM Transactions inner join Customer on Transactions.customer_id=
@Repository
public interface TransactionRepository extends JpaRepository<Transactions ,Long >{
@Query(value = "SELECT sum( value) FROM Transactions inner join Customer on Transactions.customer_id=Customer.id where merchant_id= ?1 and age_class= ?2 ", nativeQuery=true)
public double getOverAllValue(String merchantID,String ageGroup);
}
然后我尝试使用junit
测试编写的服务:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SEBApplication.class)
public class IncomeDataServiceTest {
@Autowired
IncomeDataService incomeDataService;
@Test
public void testDataCollector() {
System.out.println(incomeDataService.dataCollector(1));
}
}
但是,当我运行测试时,它会抱怨:
org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public abstract double ee.seb.domain.repository.TransactionRepository.getOverAllValue(java.lang.String,java.lang.String)
将查询的返回类型从原语数据类型
double
更新为double
,因为您的查询可以返回null
值,该值将由包装类而不是原语接受,因此您的最终查询如下:
@Query(value = "SELECT sum( value) FROM Transactions inner join Customer on Transactions.customer_id=Customer.id where merchant_id= ?1 and age_class= ?2 ", nativeQuery=true)
public Double getOverAllValue(String merchantID,String ageGroup);
将查询的返回类型从原语数据类型
double
更新为double
,因为您的查询可以返回null
值,该值将由包装类而不是原语接受,因此您的最终查询如下:
@Query(value = "SELECT sum( value) FROM Transactions inner join Customer on Transactions.customer_id=Customer.id where merchant_id= ?1 and age_class= ?2 ", nativeQuery=true)
public Double getOverAllValue(String merchantID,String ageGroup);
将查询的返回类型更改为包装类:Doubleoh man,thx。所以,
double
和double
之间有什么区别呢?将查询的返回类型更改为包装类:Doubleoh-man,thx。那么double
和double
之间有什么区别呢?