此刻,我正面臨彈簧安全(版本4)的問題。org.springframework.security.authentication.InternalAuthenticationServiceException:無法獲得JDBC連接
org.springframework.security.authentication.InternalAuthenticationServiceException: Could not get JDBC Connection
這裏了AppConfig類:
@EnableWebMvc
@Configuration
@ComponentScan({ "controller" })
@Import({ SecurityConfig.class })
public class AppConfig {
@Bean(name = "dataSource")
public DriverManagerDataSource dataSource() {
System.out.println("-------- MySQL JDBC Connection Testing ------------");
System.out.println("JDBC Driver Found");
DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
driverManagerDataSource.setDriverClassName("com.mysql.jdbc.Driver");
driverManagerDataSource.setUrl("jdbc:mysql://localhost:3306/QSQL");
driverManagerDataSource.setUsername("root");
driverManagerDataSource.setPassword("password");
return driverManagerDataSource;
}
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/Pages/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
這裏是我SecurityConfig類:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
DataSource dataSource;
@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
System.out.println("begin Auth Process");
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery(
"select username,password, enabled from QSQL.users where username=?")
.authoritiesByUsernameQuery(
"select username, role from QSQL.user_roles where username=?");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')")
.and()
.formLogin().loginPage("/login").failureUrl("/login?error")
.usernameParameter("username").passwordParameter("password")
.and()
.logout().logoutSuccessUrl("/login?logout")
.and()
.exceptionHandling().accessDeniedPage("/403")
.and()
.csrf();
}
}
但是我得到與上述沿錯誤如下:
Caused by: java.sql.SQLNonTransientConnectionException: Could not create connection to database server.
Althoug h我可以使用SQL Explorer插件連接到我的數據庫。
感謝您的幫助。
嗯我使用4.2.6春季和4.1.0春季安全...我會嘗試更新我的春季框架4.3.0。我會看看它是否修復它。 – nader
其實我發現它與mysql 6.0.2中的一個錯誤有關的錯誤......這裏:服務器時區值'EDT'是無法識別的或代表多個時區。如果要利用時區支持,則必須配置服務器或JDBC驅動程序(通過serverTimezone配置屬性)以使用更具體的時區值。 – nader