2015-08-29 4 views
0

Мое приложение не включает зависимость org.springframework.ws. Кажется, это проблема jdbc.Не удалось инициализировать класс org.springframework.jdbc.core.StatementCreatorUtils

Написание веб-приложения и практика безопасности. это сообщение появляется, когда я пытаюсь войти в базу данных mysql, называемую testdatabase.

Трассировка стека выглядит следующим образом:

SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [/SpringSecurityTut1] threw exception [Filter execution threw an exception] with root cause 
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.jdbc.core.StatementCreatorUtils 
    at org.springframework.jdbc.core.ArgumentPreparedStatementSetter.cleanupParameters(ArgumentPreparedStatementSetter.java:72) 
    at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:713) 
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:644) 
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:695) 
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:727) 
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:737) 
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:787) 
    at org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl.loadUsersByUsername(JdbcDaoImpl.java:192) 
    at org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl.loadUserByUsername(JdbcDaoImpl.java:151) 
    at org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:102) 
    at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:132) 
    at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:156) 
    at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:177) 
    at org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java:92) 
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:211) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:105) 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57) 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50) 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) 
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) 
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) 
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:724) 

Это мой SecurityConfig класс:

@Configuration 
@EnableWebMvcSecurity 
@EnableWebSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

    @Autowired 
    private DataSource dataSource; 
    @Autowired 
    public void congigureGlobal(AuthenticationManagerBuilder auth) throws Exception { 

     auth 
      .jdbcAuthentication() 
      .dataSource(dataSource); 
    } 


    public void configure(HttpSecurity http) throws Exception { 


     http    
      .authorizeRequests() 
      .antMatchers("/login").permitAll() 
      .antMatchers("/admin").hasRole("ADMIN") 
      .anyRequest().authenticated() 
      .and() 
      .formLogin() 
       .loginPage("/login").and().httpBasic(); 
    } 
} 

Это мое приложение-конфигурационный файл

<context:component-scan 
    base-package="com.springsecurityexample"/> 

<context:property-placeholder 
    location="classpath*:spring/*.properties"/> 

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> 

    <property name="driverClassName" value="com.mysql.jdbc.Driver"/> 
    <property name="url" value="jdbc:mysql://localhost:3306/testdatabase"/> 
    <property name="username" value="test"/> 
    <property name="password" value="test123"/>   

</bean> 

После я нажимаю мой логин появляется ошибка. Аналогичные вопросы о stackoverflow, похоже, указывают на проблему зависимости, но все зависимости, похоже, находятся на своем месте.

+0

Возможный дубликат [NoClassDefFound после добавления зависимости spring-ws] (http://stackoverflow.com/questions/23088165/noclassdeffound-after-adding-spring-ws-dependency) – Andreas

+0

у вас может быть несколько версий банки на ваш путь к классу. – RedDeckWins

+0

@RedDeckWins, вы имеете в виду банку org.springframework.jdbc.core. Если да, то как я могу найти источник дублирования. – abujafar

ответ

1

У меня такая же ошибка, когда я включил org.springframework.core-3.1.0.M2.jar в свой проект. Я заглянул в банку и открыл org.springframework.jdbc.core.StatementCreatorUtils класс. Я обнаружил, что он использует класс SpringProperties, который не является частью вышеуказанной банки. Я заменил выше JAR на spring-core-4.2.0.RELEASE.jar, и он начал работать.

1

Я не делал этого, кроме добавления этого файла jar в мой каталог lib для моего проекта spring-core-4.0.6.RELEASE.jar, иначе мы можем добавить это в наш путь сборки. Надеюсь, это поможет.

Смежные вопросы