Estou criando uma página de cadastro de usuários mas estou encontrando o seguinte erro:
type Exception report
message Não é possível criar instância para·a classe: managedBean.CadastroBean.
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Não é possível criar instância para·a classe: managedBean.CadastroBean. javax.faces.webapp.FacesServlet.service(FacesServlet.java:659) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) root cause
com.sun.faces.mgbean.ManagedBeanCreationException: Não é possível criar instância para·a classe: managedBean.CadastroBean. com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:191) com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:100) com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409) com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269) com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:257) com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:117) com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:80) org.apache.el.parser.AstValue.getValue(AstValue.java:135) org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184) com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) javax.faces.component.UIOutput.getValue(UIOutput.java:174) javax.faces.component.UIInput.getValue(UIInput.java:291) org.primefaces.util.ComponentUtils.getValueToRender(ComponentUtils.java:77) org.primefaces.component.inputmask.InputMaskRenderer.encodeMarkup(InputMaskRenderer.java:99) org.primefaces.component.inputmask.InputMaskRenderer.encodeEnd(InputMaskRenderer.java:57) javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312) com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185) com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129) javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856) javax.faces.render.Renderer.encodeChildren(Renderer.java:176) javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:456) com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133) com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) root cause
java.lang.ClassCastException: java.lang.String cannot be cast to org.springframework.security.core.userdetails.User managedBean.UsuarioFace.getUsu(UsuarioFace.java:45) managedBean.UsuarioFace.(UsuarioFace.java:34) managedBean.CadastroBean.(CadastroBean.java:31) sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) java.lang.reflect.Constructor.newInstance(Unknown Source) java.lang.Class.newInstance(Unknown Source) com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:186) com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:100) com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409) com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269) com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:257) com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:117) com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:80) org.apache.el.parser.AstValue.getValue(AstValue.java:135) org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184) com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) javax.faces.component.UIOutput.getValue(UIOutput.java:174) javax.faces.component.UIInput.getValue(UIInput.java:291) org.primefaces.util.ComponentUtils.getValueToRender(ComponentUtils.java:77) org.primefaces.component.inputmask.InputMaskRenderer.encodeMarkup(InputMaskRenderer.java:99) org.primefaces.component.inputmask.InputMaskRenderer.encodeEnd(InputMaskRenderer.java:57) javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312) com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185) com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129) javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856) javax.faces.render.Renderer.encodeChildren(Renderer.java:176) javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:456) com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133) com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
Descrevendo melhor: Minha aplicação já utiliza o Spring Framework e funciona normalmente, mas agora eu preciso criar uma página para que qualquer pessoa se cadastre. Então na configuração do Spring já coloquei a página como permitAll
.
Mas acontece que quando eu acesso a página ele me retorna o erro descrito. Mas quando eu logo em um usuário qualquer já cadastrado, e tento acessar a página, o acesso ocorre normalmente.
Meus códigos são o seguinte:
cadastroUsuario.xhtml
<h:body>
<h:form id="formCadastroUsuario">
<h:panelGrid id="panelUsuario" columns="2"
style="margin-bottom:10px">
<p:outputLabel for="cpf" value="CPF" />
<p:inputMask id="cpf" value="#{cadastroBean.cpf}" mask="999.999.999-99" required="true" requiredMessage="Entre com um cpf"/>
<h:outputLabel for="nascimento" value="Data Nascimento: " />
<p:calendar id="nascimento" value="#{cadastroBean.dataNascimento}" required="true" requiredMessage="Informe uma data." />
<h:outputLabel for="pass" value="Senha" />
<p:password id="pass" value="#{cadastroBean.novoUsuario.password}" redisplay="false" required="true"></p:password>
<p:commandButton action="#{cadastroBean.inserirProprioUsuario}" value="Adicionar Usuário" ajax="false"/>
</h:panelGrid>
</h:form>
cadastroBean.java (todos os getters e setters estão criados)
@ManagedBean(name="cadastroBean")
@SessionScoped
public class CadastroBean {
private UsuarioDAO usuDAO = new UsuarioDAO();
private Usuario usu;
private Usuario novoUsuario = new Usuario();
private String cpf;
private Date dataNascimento;
List<Usuario> listaUsuario = null;
public String inserirProprioUsuario(){
AlunoDAO alunoDAO = new AlunoDAO();
System.out.println(cpf);
System.out.println(dataNascimento);
Aluno a = alunoDAO.buscaAlunoPorCpf(cpf);
if (a != null){
if(a.getDataNascimento().equals(getDataNascimento())) {
if (usuDAO.getUsuarioPorMatricula(a.getMatricula()) == null){
System.out.println("Não existe login com esse aluno");
novoUsuario.setAluno(a);
novoUsuario.setPassword(criptografarSenha(novoUsuario.getPassword()));
usuDAO.inserirUsuario(novoUsuario);
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,"Sucesso","Cadastro com sucesso: "+novoUsuario.getUsername());
FacesContext.getCurrentInstance().addMessage(null, msg);
listaUsuario = null;
novoUsuario = new Usuario();
}else{
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,"Aviso","Já existe um login cadastrado com essa matrícula.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}else{
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,"Aviso","Não existe aluno cadastrado com esse CPF.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
return "usuarios";
}
security-app-context.xml
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<global-method-security secured-annotations="enabled"
jsr250-annotations="enabled" />
<http auto-config="true" use-expressions="true"
access-denied-page="/negado.jsf">
<intercept-url pattern="/login.jsf" access="permitAll" />
<intercept-url pattern="/cadastroUsuario.jsf" access="permitAll" />
<intercept-url pattern="/listaEditaisDisciplinas.jsf" access="isAuthenticated()" />
<intercept-url pattern="/realizarInscricoes.jsf" access="isAuthenticated()" />
<form-login login-page="/login.jsf" default-target-url="/realizarInscricoes.jsf"
authentication-failure-url="/login.jsf" />
<logout logout-success-url="/realizarInscricoes.jsf" />
</http>
<authentication-manager alias="authenticationManager">
<authentication-provider>
<password-encoder hash="sha-256"></password-encoder>
<jdbc-user-service data-source-ref="dataSource"
authorities-by-username-query="select username, tipoUsuario from usuario where username=?"
users-by-username-query="SELECT username, password, ativo FROM usuario WHERE username=?" />
</authentication-provider>
</authentication-manager>
<beans:bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="url"
value="jdbc:mysql://localhost:3306/monitoria" />
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<beans:property name="username" value="root" />
<beans:property name="password" value="root" />
</beans:bean>
Como resolver?