Alguém já se deparou com o erro abaixo e conseguiu solucionar? O standalone.xml e o module.xml do JBoss estão configurados corretamente, pois em outros projetos a aplicação sobe normalmente.
1) No implementation for javax.persistence.EntityManager was bound.
while locating javax.persistence.EntityManager
for parameter 0 at br.com.projeto.business.LoginBusiness.<init>(LoginBusiness.java:18)
at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.bindToConstructor(GuiceComponentRegistry.java:151)
1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:435) [guice-3.0.jar:]
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:154) [guice-3.0.jar:]
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106) [guice-3.0.jar:]
at com.google.inject.Guice.createInjector(Guice.java:95) [guice-3.0.jar:]
at com.google.inject.Guice.createInjector(Guice.java:83) [guice-3.0.jar:]
at br.com.caelum.vraptor.ioc.guice.GuiceProvider.start(GuiceProvider.java:97) [vraptor-3.5.1.jar:]
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:108) [vraptor-3.5.1.jar:]
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:102) [vraptor-3.5.1.jar:]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3865) [jbossweb-7.0.10.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_25]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_25]
00:33:45,721 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-6) Error filterStart
00:33:45,721 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-6) Context [/projeto] startup failed due to previous errors
00:33:45,736 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC00001: Failed to start service jboss.web.deployment.default-host./projeto: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./projeto: JBAS018040: Failed to start context
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:95)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_25]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_25]
00:33:45,955 INFO [org.jboss.as.jpa] (MSC service thread 1-8) JBAS011403: Stopping Persistence Unit Service 'projeto.war#default'
00:33:45,955 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "projeto.war" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.web.deployment.default-host./projeto" => "org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./projeto: JBAS018040: Failed to start context"}}
00:33:46,111 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015877: Stopped deployment projeto.war in 168ms
00:33:46,111 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014777: Services which failed to start: service jboss.web.deployment.default-host./projeto: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./projeto: JBAS018040: Failed to start context
00:33:46,126 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.web.deployment.default-host./projeto" => "org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./projeto: JBAS018040: Failed to start context"}}}}
Segue arquivos que estou utilizando:
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.com.projeto</groupId>
<artifactId>projeto</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>projeto</name>
<dependencies>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.172</version>
</dependency>
<dependency>
<groupId>br.com.caelum</groupId>
<artifactId>vraptor</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>projeto</display-name>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>br.com.projeto.i18n.messages</param-value>
</context-param>
<context-param>
<param-name>br.com.caelum.vraptor.packages</param-name>
<param-value>br.com.caelum.vraptor.util.jpa</param-value>
</context-param>
<servlet>
<servlet-name>TilesServlet</servlet-name>
<servlet-class>org.apache.tiles.web.startup.TilesServlet</servlet-class>
<init-param>
<param-name>org.apache.tiles.factory.TilesContainerFactory.MUTABLE</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
</web-app>
main/java/resources/META-INF/persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="default">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/projeto</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.connection.driver_class" value="org.h2.Driver" />
<property name="hibernate.connection.url" value="jdbc:h2:tcp://localhost/~/projeto" />
<property name="hibernate.connection.username" value="sa" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
GenericRepository
package br.com.projeto.repository.common;
import java.util.Collection;
import br.com.projeto.model.common.AbstractEntity;
public interface GenericRepository<T extends AbstractEntity> {
public T salvar(T entidade);
public void excluir(T entidade);
public T listarPorId(Long id);
public Collection<T> listar();
}
GenericBusiness
package br.com.projeto.business.common;
import java.lang.reflect.ParameterizedType;
import java.util.Collection;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import br.com.projeto.model.common.AbstractEntity;
import br.com.projeto.repository.common.GenericRepository;
public abstract class GenericBusiness<T extends AbstractEntity> implements
GenericRepository<T> {
protected final EntityManager manager;
private final Class<T> classe;
protected GenericBusiness(EntityManager manager) {
this.manager = manager;
@SuppressWarnings("unchecked")
Class<T> classe = (Class<T>) ((ParameterizedType) getClass()
.getGenericSuperclass()).getActualTypeArguments()[0];
this.classe = classe;
}
@Override
public T salvar(T entidade) {
return manager.merge(entidade);
}
@Override
public void excluir(T entidade) {
manager.remove(manager.getReference(classe, entidade.getId()));
}
@Override
public T listarPorId(Long id) {
return manager.find(classe, id);
}
@Override
public Collection<T> listar() {
Query query = manager.createNamedQuery(classe.getName() + ".listar");
@SuppressWarnings("unchecked")
Collection<T> list = query.getResultList();
return list;
}
}
LoginRepository
package br.com.projeto.repository;
import br.com.projeto.model.Usuario;
public interface LoginRepository {
public Usuario autenticar(String email, String senha);
}
LoginBusiness
package br.com.projeto.business;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import br.com.caelum.vraptor.ioc.Component;
import br.com.projeto.model.Usuario;
import br.com.projeto.repository.LoginRepository;
@Component
public class LoginBusiness implements LoginRepository {
private EntityManager manager;
public LoginBusiness(EntityManager manager) {
this.manager = manager;
}
public Usuario autenticar(String email, String senha) {
try {
Query query = manager
.createNamedQuery("Usuario.listarPorLoginSenha");
query.setParameter("email", email);
query.setParameter("senha", senha);
return (Usuario) query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
}
LoginController
package br.com.projeto.controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.projeto.component.UsuarioSessao;
import br.com.projeto.model.Usuario;
import br.com.projeto.repository.LoginRepository;
import br.com.projeto.util.JavaUtil;
@Resource
@Path("/login")
public class LoginController {
private final Result result;
private final LoginRepository repository;
private final UsuarioSessao usuarioSessao;
public LoginController(Result result, LoginRepository repository,
UsuarioSessao usuarioSessao) {
this.result = result;
this.repository = repository;
this.usuarioSessao = usuarioSessao;
}
@Post("/autenticar")
public void autenticar(Usuario usuario) {
Usuario u = repository.autenticar(usuario.getEmail(),
usuario.getSenha());
if (!JavaUtil.isObjetoVazio(u)) {
usuarioSessao.setUsuario(u);
result.redirectTo(HomeController.class).index();
} else {
result.redirectTo(this).index();
}
}
}
UsuarioSessao
package br.com.projeto.component;
import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.ioc.SessionScoped;
import br.com.projeto.model.Usuario;
import br.com.projeto.util.JavaUtil;
@Component
@SessionScoped
public class UsuarioSessao {
private Usuario usuario;
public boolean isLogado() {
return !JavaUtil.isObjetoVazio(usuario);
}
public void logout() {
usuario = null;
}
public Usuario getUsuario() {
return usuario;
}
public void setUsuario(Usuario usuario) {
this.usuario = usuario;
}
}
login.jsp
<form action="${linkTo[LoginController].autenticar}" method="post">
<p>
<label for="user_email">E-mail:<br />
<input type="text" name="usuario.email" class="input" size="20" tabindex="10" value="${usuario.email}" /></label>
</p>
<p>
<label for="user_pass">Senha:<br />
<input type="password" name="usuario.senha" class="input" size="20" tabindex="20" /></label>
</p>
<p class="submit">
<input type="submit" value="Entrar" tabindex="100" />
</p>
</form>