I have a rather naive question. Can we embed dependencies using the java core in the same way as we implement using the Spring framework?
I am currently doing something like this:
In web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
spring applicationcontext.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="mybean" class="com.test.app.MyService" />
</beans>
The class where I will use the entered bean:
public class MyResource {
@Autowired
private MyService mybean;
public MyResponse doService(MyRequest req) {
mybean.doBusiness(req);
}
}
}
So, is there a way to do this dependency injection using the java kernel? I read a little CDI, but did not understand it well. In addition, he also felt that it was not a direct replacement for what Spring is doing.
Please help and correct me if I am wrong.
source
share