Betrachten Spring Boot zu verwenden !
als du so etwas tun kann ...
Runner:
@SpringBootApplication
public class Runner{
public static void main(String[] args) {
SpringApplication.run(Runner.class, args);
}
}
Einige Controller:
@Controller
public class MyController {
// Spring Boot injecting beans through @Autowired annotation
@Autowired
@Qualifier("CoolFeature") // Use Qualifier annotation to mark a class, if for example
// you have more than one concreate class with differant implementations of some interface.
private CoolFeature myFeature;
public void testFeature(){
myFeature.doStuff();
}
}
Einige cooles Feature:
@Component("CoolFeature") // To identify with Qualifier
public class CoolFeature{
@Autowired
private SomeOtherBean utilityBean;
public void doStuff(){
// use utilityBean in some way
}
}
Keine XML-Dateien zu behandeln. Wir können bei Bedarf weiterhin auf den Kontext für manuelle Konfigurationen zugreifen.
nachlesen:
Spring Boot Reference
Pro Spring Boot
http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#beans-factory -scopes-sing-prot-Interaktion –