Tela de login com primefaces

5 respostas
C
Bom dia pessoal. Estou tendo problemas poara fazer uma tela de login usando primefaces, spring security, maven e o servidor jboss 7.1.1. Meu projeto esta assim: XHTML:
<h:form prependId="false">
	   		<p:dialog header="Area restrita"
	   				  modal="true"
	   				  closable="false"
	   				  position="center"
	   				  widgetVar="modalLogin"
	   				  minWidth="300"
	   				  width="300"
	   				  showEffect="slide" 
	   		    	  draggable="false"
	   		    	  resizable="false"
	   		    	  visible="true">		 
	   			<center>	 
				   	<p:messages id="mensagens" showDetail="true" showSummary="false" />    				 
		   			<h:panelGrid columns="2">   		
				      	<h:outputLabel value="Login" />
		     			<h:inputText id="j_username" size="15" />
				 		<h:outputLabel value="Senha" />
						<h:inputSecret id="j_password" size="15" />
					</h:panelGrid>
					<br />	
					<h:commandButton value="Entrar" action="#{loginMB.logar}" />		
				</center>
			</p:dialog>
	 	</h:form>
Bean:
public String logar() {
		try {
		    RequestDispatcher dispatcher = FacesUtil.getServletRequest().getRequestDispatcher("/j_spring_security_check");
		    dispatcher.forward(FacesUtil.getServletRequest(), FacesUtil.getServletResponse());
		    FacesContext.getCurrentInstance().responseComplete();
		} catch (Exception ex) {
			FacesUtil.exibirMensagemErro(ex.getMessage());
			return null;
		}
	    return null;
	}
	
	public String logout() {
		FacesUtil.exibirMensagemAlerta("Sess&#65533;o finalizada com sucesso");
		try {
			RequestDispatcher dispatcher = FacesUtil.getServletRequest().getRequestDispatcher("/j_spring_security_logout");
			dispatcher.forward(FacesUtil.getServletRequest(), FacesUtil.getServletResponse());
			FacesContext.getCurrentInstance().responseComplete();
		} catch (Exception ex) {
			FacesUtil.exibirMensagemErro("Erro ao sair do sistema");
			return null;
		}
		return null;
	}
SERVICE:
@Service("hibernateUserDetailsService")
public class HibernateUserDetailsService extends HibernateDaoSupport implements UserDetailsService  {
	@Autowired
	public HibernateUserDetailsService(SessionFactory sessionFactory) {
		setSessionFactory(sessionFactory);
	}

	@SuppressWarnings("unchecked")
	@Override
	public UserDetails loadUserByUsername(String login) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Usuario.class, "usuario");
		criteria.add(Restrictions.eq("usuario.login", login));
		List resultado = getHibernateTemplate().findByCriteria(criteria);
		if(resultado != null && resultado.size() == 0) {
			throw new UsernameNotFoundException("Usuario nao encontrado!");
	    }	
		return (Usuario)resultado.get(0);
	}
}
spring-config.xml:
<bean class="springframework.orm.hibernate3.HibernateExceptionTranslator"/>
   <bean id="sessionFactory"   class="springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="annotatedClasses">
			<list>
				<value>br.com.exemploseguranca.entity.Usuario</value>
				<value>br.com.exemploseguranca.entity.Perfil</value>
				<value>br.com.exemploseguranca.entity.Carreta</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
				<prop key="hibernate.show_sql">true</prop>
			</props>
		</property>
	</bean>
O progrema é que esta dando esses erros na hora de startar o JBoss:
ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-2) Context initialization failed: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'hibernateUserDetailsService' defined in "/C:/jboss-as-7.1.1.Final/standalone/deployments/seguranca.war/WEB-INF/classes/br/com/exemploseguranca/service/HibernateUserDetailsService.class": Unsatisfied dependency expressed through constructor argument with index 0 of type [org.hibernate.SessionFactory]: : Cannot find class [springframework.orm.hibernate3.HibernateExceptionTranslator] for bean with name 'springframework.orm.hibernate3.HibernateExceptionTranslator#0' defined in ServletContext resource [/WEB-INF/spring-config.xml]; nested exception is java.lang.ClassNotFoundException: springframework.orm.hibernate3.HibernateExceptionTranslator from [Module "deployment.seguranca.war:main" from Service Module Loader]; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [springframework.orm.hibernate3.HibernateExceptionTranslator] for bean with name 'springframework.orm.hibernate3.HibernateExceptionTranslator#0' defined in ServletContext resource [/WEB-INF/spring-config.xml]; nested exception is java.lang.ClassNotFoundException: springframework.orm.hibernate3.HibernateExceptionTranslator from [Module "deployment.seguranca.war:main" from Service Module Loader]
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [springframework.orm.hibernate3.HibernateExceptionTranslator] for bean with name 'springframework.orm.hibernate3.HibernateExceptionTranslator#0' defined in ServletContext resource [/WEB-INF/spring-config.xml]; nested exception is java.lang.ClassNotFoundException: springframework.orm.hibernate3.HibernateExceptionTranslator from [Module "deployment.seguranca.war:main" from Service Module Loader]
Caused by: java.lang.ClassNotFoundException: springframework.orm.hibernate3.HibernateExceptionTranslator from [Module "deployment.seguranca.war:main" from Service Module Loader]

Alguém pode me ajudar????

5 Respostas

R

batendo o olho parece que estão faltando dependências (jars), ou eles não estão configurados corretamente.

você tem o jar com essa classe que ele diz que está faltando no seu projeto ?

C

Eu também achei que era isso, mas eu tenho o juar que tem essa classe…

R

provavelmente ele não está no lugar certo então… pelo que o erro diz, ele deveria estar dentro do seu war

C

Mas ele esta lá nas dependencias do maven junto com todas as outras libs…

C

Mudei meu spring-config.xml, ficou assim:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="annotatedClasses"> <list> <value>br.com.exemploseguranca.entity.Usuario</value> <value>br.com.exemploseguranca.entity.Perfil</value> <value>br.com.exemploseguranca.entity.Carreta</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean>
e dai da esse erro:

Criado 2 de maio de 2012
Ultima resposta 2 de mai. de 2012
Respostas 5
Participantes 2