I defined the MyFrontService class in the bank, this is how I want to use it:
import blabla.MyFrontService; public class Main { public static void main(String[] args) { MyFrontService.doThis(); } }
FrontService serves as an entry point for accessing other services. This is how it is currently defined (and it works).
MyFrontService.java:
public class MyFrontService { public static void doThis(){ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/springBeans.xml"); MyService1 myService1 = (MyService1) context.getBean("myService1"); myService1.doSomething(); context.close(); } }
MyService1.java:
package blabla.service; @Service("myService1") public class MyService1 { public void doSomething(){
SRC / main / resources / META-INF / springBeans.xml:
(...) <context:annotation-config /> <context:component-scan base-package="blabla.service" /> (...)
I would like to replace the MyFrontService.java code with something like this:
@MagicAnnotation("what_path?/springBeans.xml") public class MyFrontService { @Autowired private static MyService1 myService1; public static void doThis(){ myService1.doSomething(); } }
I read a lot from other questions on this site and others. Sometimes they say that this is impossible, and sometimes annotations such as @Configuration, @Import and others are used, but I can not get them to work. For example, using
@ImportResource("classpath:META-INF/springBeans.xml")
throws a NullPointerException when calling myService1.doSomething ().
If possible, which annotation and which way should I use?
source share