Skip to main content

Problem to set the Spring Security 3

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
regisosantosgmailcom
Offline
Joined: 2011-09-23

Configuring the Spring Security.

I can not identify the problem shown below.

I use the Java 6.0 and Eclipse.

Console's error:

23/09/2011 15:01:51 org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "com.sun.faces.config.ConfigureListener" is already configured for this context. The duplicate definition has been ignored.
23/09/2011 15:01:52 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
23/09/2011 15:01:58 org.apache.catalina.core.StandardContext listenerStart
GRAVE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cartaoCreditoDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory dao.GenericoDAO.sessionFactory; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.security.event.authorization.LoggerListener] for bean with name 'org.springframework.security.event.authorization.LoggerListener#0' defined in ServletContext resource [/WEB-INF/spring-security-config.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.security.event.authorization.LoggerListener
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4323)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4780)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:988)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:771)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:988)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:275)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:427)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:649)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.startup.Catalina.start(Catalina.java:585)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:415)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory dao.GenericoDAO.sessionFactory; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.security.event.authorization.LoggerListener] for bean with name 'org.springframework.security.event.authorization.LoggerListener#0' defined in ServletContext resource [/WEB-INF/spring-security-config.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.security.event.authorization.LoggerListener
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
... 33 more
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.security.event.authorization.LoggerListener] for bean with name 'org.springframework.security.event.authorization.LoggerListener#0' defined in ServletContext resource [/WEB-INF/spring-security-config.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.security.event.authorization.LoggerListener
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1319)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:315)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:185)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:829)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:786)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
... 35 more
Caused by: java.lang.ClassNotFoundException: org.springframework.security.event.authorization.LoggerListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1666)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1511)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:257)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:408)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1271)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1242)
... 43 more
23/09/2011 15:01:58 com.sun.faces.config.ConfigureListener contextInitialized
INFO: Inicializando Mojarra 2.1.1 (FCS 20110408) para o contexto '/regisecommerce'
23/09/2011 15:02:00 com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: Anotações PostConstruct/PreDestroy presentes. Os métodos ManagedBeans marcados com essas anotações informarão as anotações processadas.
23/09/2011 15:02:01 org.apache.catalina.core.StandardContext startInternal
GRAVE: Error listenerStart
23/09/2011 15:02:01 org.apache.catalina.core.StandardContext startInternal
GRAVE: Context [/regisecommerce] startup failed due to previous errors
23/09/2011 15:02:01 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
23/09/2011 15:02:01 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
GRAVE: The web application [/regisecommerce] registered the JBDC driver [org.postgresql.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
23/09/2011 15:02:01 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
GRAVE: The web application [/regisecommerce] created a ThreadLocal with key of type [null] (value [javax.faces.context.FacesContext$1@11c7eb2]) and a value of type [com.sun.faces.config.InitFacesContext] (value [com.sun.faces.config.InitFacesContext@1c21535]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.

file: applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<!-- Fonte de dados: driver e nome banco de dados, usuário, senha -->
<bean id="dataSource" class="config.Conexao" />

<!-- configuração do Hibernate -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
scope="singleton" lazy-init="false" autowire="default">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="c3p0.acquire_increment">1</prop>
<prop key="c3p0.idle_test_period">120</prop>
<prop key="c3p0.max_size">50</prop>
<prop key="c3p0.max_statements">100</prop>
<prop key="c3p0.min_size">5</prop>
<prop key="c3p0.timeout">150</prop>
</props>
</property>
<property name="annotatedClasses">
<!-- lista de classes sendo adicionados a serem manipuladas pelo Hibernate -->
<list>
<value>entidade.Pais</value>
<value>entidade.Produto</value>
<value>entidade.Produto</value>
<value>entidade.Uf</value>
<value>entidade.Estoque</value>
<value>entidade.Cidade</value>
<value>entidade.Fabricante</value>
<value>entidade.ItemVendido</value>
<value>entidade.Venda</value>
<value>entidade.Representante</value>
<value>entidade.Envio</value>
<value>entidade.CartaoCredito</value>
<value>entidade.Cliente</value>
<value>entidade.Usuario</value>
<value>entidade.Perfil</value>
<value>entidade.Configuracao</value>
</list>
</property>
</bean>

<bean class="seguranca.TesteEventListener"/>

<!-- <tx:annotation-driven mode="proxy"/> -->

<!-- Gerenciador de transação
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean> -->

<!-- Possibilitando que se use anotação -->
<context:annotation-config/>

<!-- Habilitando que o Spring examine nos pacotes aqui definidos
por @Component, @Service, @Controller, Autowired -->
<context:component-scan base-package="dao, controle, modelo" />

</beans>

file: spring-security-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.0.xsd">

<http auto-config="true" access-denied-page="/accessoNegado.jsp">
<intercept-url pattern="/usuarios/**" access="ROLE_USUARIO, ROLE_ADMIN"/>
<intercept-url pattern="/administrador/**" access="ROLE_ADMIN"/>
<form-login login-page="/login.jsp" authentication-failure-url="login.jsp?login_error=true"
default-target-url="/index.jsp"/>
<logout logout-url="/logout"/>
</http>

<authentication-manager>
<authentication-provider user-service-ref="hibernateUserDetailsService" ref="daoAuthenticationProvider" />
</authentication-manager>

<beans:bean id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<beans:property name="userDetailsService" ref="hibernateUserDetailsService" />
</beans:bean>

<beans:bean class="seguranca.EventListenerSenhaIncorreta"/>

<beans:bean class="org.springframework.security.event.authorization.LoggerListener"/>

<beans:bean class="org.springframework.security.event.authorization.LoggerListener"/>

</beans:beans>

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tobimichigan
Offline
Joined: 2011-09-03

The problem was stated at the beginning:

"

log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.

"