Tomcat Can';不要做焊缝扫描豆
我一定错过了什么,但我不能让焊接工作! 这是一个简单的webapp,一个servlet,一个服务(我想把它注入servlet) 以下是文件: pom.xmlTomcat Can';不要做焊缝扫描豆,tomcat,servlets,cdi,weld,Tomcat,Servlets,Cdi,Weld,我一定错过了什么,但我不能让焊接工作! 这是一个简单的webapp,一个servlet,一个服务(我想把它注入servlet) 以下是文件: pom.xml <dependency> <groupId>org.jboss.weld.servlet</groupId> <artifactId>weld-servlet-core</artifactId> <version>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-core</artifactId>
<version>2.3.4.Final</version>
</dependency>
我的servlet:
public class Hello extends HttpServlet {
@Inject
private ServiceTest service;
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// Set the response message's MIME type.
response.setContentType("text/html;charset=UTF-8");
// Allocate a output writer to write the response message into the network socket.
PrintWriter out = response.getWriter();
try {
out.println("<!DOCTYPE html>"); // HTML 5
out.println("<html><head>");
out.println("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>");
String title = service.test();
out.println("<title>" + title + "</title></head>");
out.println("<body>");
out.println("<h1>" + title + "</h1>"); // Prints "Hello, world!"
out.println("</body></html>");
} finally {
out.close(); // Always close the output writer
}
}
}
beans.xml(在META-INF下)
2016-06-07 22:49:27信息引导:166-WELD-ENV-000028:已跳过焊接初始化-未找到bean存档
这意味着Weld在您的战争中没有找到任何bean存档。注意,在战争中,beans.xml
必须命名为WEB-INF/beans.xml
或WEB-INF/classes/META-INF/beans.xml
(另请参见规范)。我猜您有META-INF/beans.xml
2016-06-07 22:49:27信息引导:166-WELD-ENV-000028:已跳过焊接初始化-未找到bean存档
这意味着Weld在您的战争中没有找到任何bean存档。注意,在战争中,
beans.xml
必须命名为WEB-INF/beans.xml
或WEB-INF/classes/META-INF/beans.xml
(另请参见规范)。我猜你有META-INF/beans.xml
请用NPE发布你的堆栈跟踪。你有beans.xml吗?NPE没有提供任何信息,只需调用注入的对象,该对象为空。我已经添加了META-INF中的beans.xml。您是否读到应该将beans.xml
放在WAR存档的/META-INF
中?请使用NPE发布堆栈跟踪。您是否在某处有beans.xml?NPE没有提供任何信息,只需调用注入的对象,该对象为空。我已经添加了META-INF中的beans.xml。您是否读到应该将beans.xml
放在WAR存档的/META-INF
中?
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
@Named
@SessionScoped
public class ServiceTest {
public String test(){
return "hello world";
}
}
public class Hello extends HttpServlet {
@Inject
private ServiceTest service;
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// Set the response message's MIME type.
response.setContentType("text/html;charset=UTF-8");
// Allocate a output writer to write the response message into the network socket.
PrintWriter out = response.getWriter();
try {
out.println("<!DOCTYPE html>"); // HTML 5
out.println("<html><head>");
out.println("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>");
String title = service.test();
out.println("<title>" + title + "</title></head>");
out.println("<body>");
out.println("<h1>" + title + "</h1>"); // Prints "Hello, world!"
out.println("</body></html>");
} finally {
out.close(); // Always close the output writer
}
}
}
2016-06-07 22:49:27 DEBUG logging:37 - Logging Provider: org.jboss.logging.Log4jLoggerProvider
2016-06-07 22:49:27 INFO servletWeldServlet:57 - WELD-ENV-001008: Initialize Weld using ServletContainerInitializer
2016-06-07 22:49:27 INFO Version:153 - WELD-000900: 2.3.4 (Final)
2016-06-07 22:49:27 DEBUG Bootstrap:121 - WELD-ENV-000030: Cannot load class using the ResourceLoader: org.jboss.jandex.Index
2016-06-07 22:49:27 DEBUG Bootstrap:121 - WELD-ENV-000030: Cannot load class using the ResourceLoader: org.jboss.jandex.Index
2016-06-07 22:49:27 DEBUG Bootstrap:316 - WELD-ENV-000024: Archive isolation enabled - creating multiple isolated bean archives if needed
2016-06-07 22:49:27 INFO Bootstrap:166 - WELD-ENV-000028: Weld initialization skipped - no bean archive found
juin 07, 2016 10:49:27 PM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["http-bio-8080"]
juin 07, 2016 10:49:27 PM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["ajp-bio-8009"]
juin 07, 2016 10:49:27 PM org.apache.catalina.startup.Catalina start
INFOS: Server startup in 1127 ms
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee">
<scan>
</scan>
</beans>