0
我試圖讓DI與示例DynamoDBTypeConverter一起工作我在玩弄,並沒有運氣:(我的服務始終爲空,並在我的jUnit中引發錯誤。測試 這裏是我的轉換器:Spring Boot + DynamoDBTypeConverter依賴注入
@Component
public class ArmTypeConverter implements DynamoDBTypeConverter<String, Arm> {
@Autowired
private ArmRepository armRepository;
@Override
public String convert(Arm Arm) {
return arm.getId();
}
@Override
public Arm unconvert(String id) {
return armRepository.findOne(id);
}
}
我的應用程序主:
@SpringBootApplication
@ComponentScan
@EnableSpringConfigured
@EnableLoadTimeWeaving(aspectjWeaving=EnableLoadTimeWeaving.AspectJWeaving.ENABLED)
@EnableAutoConfiguration
public class ArmApplication implements ApplicationRunner {
public static void main(String[] args) {
SpringApplication.run(ArmApplication.class, args);
}
@Bean
public InstrumentationLoadTimeWeaver loadTimeWeaver() throws Throwable {
InstrumentationLoadTimeWeaver loadTimeWeaver = new InstrumentationLoadTimeWeaver();
return loadTimeWeaver;
}
}
我的服務:
@Service
public class ArmServiceImpl implements ArmService {
@Autowired
private ArmRepository armRepository;
@Override
public Arm create(String length, Set<Register> registers) {
Date now = new Date();
Arm arm = new Arm();
arm.setLength("85cm");
return armRepository.save(arm);
}
}
我的測試:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class ArmServiceTests {
@Autowired
private ArmService armService;
@Autowired
private TorsoService torsoService;
private Arm arm;
@Before
public void before() {
arm = armService.create("85cm", null);
torsoService.create("150cm", arm);
}
@After
public void after() {
// do nothing for now...
}
@Test
@WithUserDetails("[email protected]")
public void getArmTest() {
Arm c = armService.getArm(arm.getId());
assertThat(c).isNotNull();
assertThat(c.getId()).isEqualTo(arm.getId());
}
}
我在做什麼錯?
你可以顯示服務和junit代碼。 – pkoli
我更新了OP – user1170235
我們是否也可以有原木 – pkoli