I am using Spring Boot to create a micro service, and all is well, except for a couple of minor annoyances.
Autowiring in my test classes, I am getting the following warnings on @Autowired annotations:
Autowired members must be defined in the valid spring bean(@Component/@Service,etc.) Checks that auto wired members are defined in valid Spring bean (@Component|@Service|...).
this is using the following test class
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
public class MyRecordTest {
public static final String NUMBER = "ABC/123456";
@Autowired
private MyFactory factory;
@Autowired
private Marshaller marshaller;
...
}
where my Application configuration class is defined as
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public Marshaller getMarshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("com.my.classes");
return marshaller;
}
}
and MyFactory has the @Component annotation:
@Component
public class MyFactory {
...
}
How can I resolve this?
Also, standing out like a sore thumb, the only uncovered line in my application is the SpringApplication.run line in the public static void main method:
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
How can I get this covered or ignored?
Aucun commentaire:
Enregistrer un commentaire