1 pièce(s) jointe(s)
NullPointerException au lancement de l'application
Bonjour,
je développe une application basée sur spring
L'application démarre sans erreur sous eclipse. Je suis confronté à 2 erreurs
1) quand je lance depuis mon navigateur la page de login (http://localhost:8080/TennisArc1600/login.jsp) (mon projet se nomme TennisArc1600), j'ai l'erreur suivante qui s'affiche:
Code:
1 2 3 4 5 6
|
La page n'est pas redirigée correctement
Firefox a détecté que le serveur redirige la demande pour cette adresse d'une manière qui n'aboutira pas.
La cause de ce problème peut être la désactivation ou le refus des cookies. |
j'utilise spring security. Mon fichier xml est le suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<security:http auto-config="true">
<security:intercept-url pattern="/**" access="hasRole('ROLE_MEMBRE')" />
<security:form-login login-page="/login.jsp"
default-target-url="/WEB-INF/pages/index.jsp"
authentication-failure-url="/login?error" username-parameter="username"
password-parameter="password" />
<security:logout logout-success-url="/login?logout" />
<!-- enable csrf protection -->
<security:csrf />
<security:custom-filter after="FORM_LOGIN_FILTER"
ref="authenticationFilter" />
</security:http>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider
ref="authenticationProvider" />
</security:authentication-manager>
<bean id="authenticationProvider"
class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<property name="userDetailsService" ref="userDetailsService" />
<property name="passwordEncoder" ref="encoder" />
</bean>
<bean id="encoder"
class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" />
<bean id="userDetailsService" class="spring.security.UserDetailsServiceImpl" />
<bean id="passwordChecker" class="spring.security.impl.PasswordCheckerImpl" />
<bean id="authenticationFilter"
class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter">
<property name="authenticationManager" ref="authenticationManager" />
<property name="filterProcessesUrl" value="/login" />
<property name="authenticationSuccessHandler" ref="authenticationSuccessHandler" />
<property name="authenticationFailureHandler" ref="authenticationFailureHandler" />
</bean>
<bean id="authenticationSuccessHandler" class="spring.security.AuthenticationSuccessHandlerImpl">
<property name="defaultTargetUrl" value="/WEB-INF/pages/index.jsp" />
<property name="userManagementService" ref="userManagementService" />
</bean>
<bean id="authenticationFailureHandler" class="spring.security.AuthenticationFailureHandlerImpl">
<property name="defaultFailureUrl" value="/login.jsp" />
<property name="userManagementService" ref="userManagementService" />
</bean>
<bean id="userManagementService" class="spring.security.UserDetailsServiceImpl">
</bean>
</beans> |
l'arborexcence de mon projet est le suivant
Pièce jointe 180542
2) deuxième erreur: quand je rentre l'adresse http://localhost:8080/TennisArc1600/login j'ai une null pointer exception à la ligne marquée en rouge : membreDao est null
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
package spring.security;
.................
public class UserDetailsServiceImpl implements UserDetailsService, MessageSourceAware {
................................
@Autowired
@Qualifier("membreDao")
private JpaDAO membreDao;
............................
public Membre getMembreByLogin(String login) {
final List<Membre> membres = this.membreDao.executeNamedQuery("findByLogin", "login", login);
Membre membre = null;
if (membres.size() == 1) {
membre = membres.get(0);
}
return membre;
}
...............................
} |
voici la definition de membreDao dans mon fichier xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.0.xsd">
<bean id="JpaDAOImpl" class="orm.impl.JpaDAOImpl" abstract="true"/>
<bean id="membreDao" parent="JpaDAOImpl">
<constructor-arg value="domain.Membre" />
</bean>
</beans> |
et voici la classe JpaDAOImpl et JpaDAO
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
import orm.JpaDAO;
@Repository
@Transactional(readOnly = true)
public class JpaDAOImpl< T extends Serializable > implements JpaDAO<T> {
.....................
private Class< T > clazz;
@PersistenceContext
EntityManager entityManager;
public JpaDAOImpl(Class< T > clazz) {
this.clazz = clazz;
}
..........................
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
package orm;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
public interface JpaDAO<T extends Serializable> {
public abstract T create(T entity);
public abstract void delete(T entity);
public abstract void deleteById(Integer entityId);
/**
* @param namedQuery
* @param params
* @return
*/
public abstract List<T> executeNamedQuery(String namedQuery,
Map<String, Object> params);
public abstract List<T> executeNamedQuery(String namedQuery,
Map<String, Object> params, int maxResults);
/**
* @param namedQuery
* @param paramName
* @param paramValue
* @return
*/
public abstract List<T> executeNamedQuery(String namedQuery,
String paramName, Object paramValue);
/**
* @param namedQuery
* @param paramName
* @param paramValue
* @return
*/
public abstract List<T> executeNamedQuery(String namedQuery,
String paramName, Object paramValue, int maxResults);
/**
* @param nativeQuery
* @return
*/
public abstract List<T> executeNativeQuery(String nativeQuery);
/**
* @param nativeQuery
* @return
*/
public abstract int executeNativeUpdateQuery(String nativeQuery);
/**
* @param jpqlQuery
* @param params
* @return
*/
public abstract int executeUpdateQuery(String jpqlQuery,
Map<String, Object> params);
public abstract List<T> findAll();
public abstract T findOne(Integer id);
public abstract T read(Integer entityId);
public abstract void save(T entity);
public abstract void setClazz(Class<T> clazzToSet);
public abstract void update(T entity);
} |
j'utilise le fichier de configuration suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
package orm;
import java.util.Properties;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@ComponentScan("domain")
@EnableTransactionManagement
public class PersistenceJPAConfig{
@Value("${jdbc.dialect}")
private String dialect;
@Value("${jdbc.driverClassName}")
private String driverClassName;
@Value("${jdbc.hbm2ddl}")
private String hbm2ddl;
@Value("${jdbc.password}")
private String password;
@Value("${jdbc.url}")
private String url;
@Value("${jdbc.username}")
private String username;
Properties additionalProperties() {
final Properties properties = new Properties();
properties.setProperty("hibernate.hbm2ddl.auto", this.hbm2ddl);
properties.setProperty("hibernate.dialect", this.dialect);
return properties;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(){
final LocalContainerEntityManagerFactoryBean factoryBean
= new LocalContainerEntityManagerFactoryBean();
factoryBean.setDataSource( restDataSource() );
factoryBean.setPackagesToScan( new String[ ] { "domain" } );
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setDatabase(Database.MYSQL);
vendorAdapter.setShowSql(true);
vendorAdapter.setGenerateDdl(true);
factoryBean.setJpaVendorAdapter( vendorAdapter );
factoryBean.setJpaProperties( additionalProperties() );
return factoryBean;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){
return new PersistenceExceptionTranslationPostProcessor();
}
@Bean
public DataSource restDataSource(){
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName( this.driverClassName );
dataSource.setUrl( this.url );
dataSource.setUsername( this.username );
dataSource.setPassword( this.password );
return dataSource;
}
@Bean
public PlatformTransactionManager transactionManager(){
final JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(
entityManagerFactoryBean().getObject() );
return transactionManager;
}
} |
Merci d'avance pour vos suggestion