标签:cdi aop
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> </beans>
package com.zhouxiang; import java.io.IOException; import javax.inject.Inject; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class CDITest */ public class CDITest extends HttpServlet { private static final long serialVersionUID = 1L; @Inject private Test1 test; /** * @see HttpServlet#HttpServlet() */ public CDITest() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request,response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub System.out.println("dsfsdfsd"); test.test(); } }
package com.zhouxiang; import javax.enterprise.inject.Default; import javax.inject.Inject; import javax.inject.Named; @Default public class Test1 { public void test() { System.out.println("hello inject!"); } }
Context Depedency Injection(一)
标签:cdi aop
原文地址:http://blog.csdn.net/leimengyuanlian/article/details/43986569