2016-06-07 3 views
0

Я, должно быть, что-то пропустил, но я не могу заставить Weld работать! Это простой веб-приложение, один сервлет, один сервис (который я хотел бы, чтобы ввести в сервлет)Не удается изготовить сканирующие бобы сварки

здесь файлы:

pom.xml

<dependency> 
     <groupId>org.jboss.weld.servlet</groupId> 
     <artifactId>weld-servlet-core</artifactId> 
     <version>2.3.4.Final</version> 
    </dependency> 

context.xml

<Context> 
     <Resource name="BeanManager" 
      auth="Container" 
      type="javax.enterprise.inject.spi.BeanManager" 
      factory="org.jboss.weld.resources.ManagerObjectFactory"/> 
    </Context> 

моя служба

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 
      } 
     } 
} 

Я не хочу просто получить NPE ... ничего.

здесь является стартовым след моей Tomcat 7

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 

beans.xml (в META-INF)

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"> 
    <scan> 

    </scan> 
</beans> 
+0

Пожалуйста, разместите свою трассировку стека с помощью NPE. –

+0

У вас есть beans.xml где-нибудь? – temaleva

+0

NPE не дает никакой информации, просто вызов инжектируемого объекта, который является нулевым. – Seb

ответ

2

2016-06-07 22:49:27 INFO Bootstrap : 166 - WELD-ENV-000028: Инициализация сварки пропущена - не найден архив бобов

Это означает, что Weld не нашел bean-архив в вашей WAR. Обратите внимание, что в WAR, beans.xml необходимо называть WEB-INF/beans.xml или WEB-INF/classes/META-INF/beans.xml (см. Также спецификацию 12.1. Bean archives). Я предполагаю, что у вас есть META-INF/beans.xml.