【发布时间】:2020-08-25 04:49:00
【问题描述】:
我正在使用 spring boot 和 spring security 和 jsp 做一个 MVC 项目。我只是在训练我的弹簧,我有同样的项目在没有弹簧靴的情况下运行。目前我搬到了springboot,当我尝试开始时,我得到:
2020-05-09 17:28:38.521 信息 21308 --- [restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]:初始化 Spring 嵌入式 WebApplicationContext 2020-05-09 17:28:38.527 信息 21308 --- [restartedMain] os.web.context.ContextLoader:根 WebApplicationContext:初始化在 6813 毫秒内完成 2020-05-09 17:28:38.753 WARN 21308 --- [restartedMain] ConfigServletWebServerApplicationContext:遇到异常 在上下文初始化期间 - 取消刷新尝试: org.springframework.beans.factory.UnsatisfiedDependencyException: 创建名为“inMemoryDatabaseShutdownExecutor”的 bean 时出错 在类路径资源中定义 [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class]: 通过方法表达的不满足的依赖关系 'inMemoryDatabaseShutdownExecutor' 参数 0;嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 创建在类路径资源中定义的名称为“dataSource”的bean [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: 通过工厂方法实例化 Bean 失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:失败 实例化 [com.zaxxer.hikari.HikariDataSource]:工厂方法 'dataSource' 抛出异常;嵌套异常是 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: 无法确定合适的驱动程序类 2020-05-09 17:28:38.769 信息 21308 --- [restartedMain] o.apache.catalina.core.StandardService :停止服务 [Tomcat] 2020-05-09 17:28:38.826 信息 21308 --- [restartedMain] ConditionEvaluationReportLoggingListener:
***************************应用程序启动失败
说明:
未能配置数据源:未指定“url”属性并且 无法配置嵌入式数据源。
原因:无法确定合适的驱动程序类
我不知道发生了什么。
application.properties
# JDBC properties
#
app.datasource.url=jdbc:mysql://localhost:3306/web_customer_tracker?useSSL=false&serverTimezone=UTC
app.datasource.username=springstudent
app.datasource.password=springstudent
# Spring Data JPA properties
spring.data.jpa.repository.packages=com.crm.dao
spring.data.jpa.entity.packages-to-scan=com.crm.beans
#
# SECURITY JDBC properties
#
security.datasource.jdbc-url=jdbc:mysql://localhost:3306/spring_security_demo_bcrypt?useSSL=false&serverTimezone=UTC
security.datasource.username=springstudent
security.datasource.password=springstudent
security.datasource.driver-class-name= com.mysql.jdbc.Driver
配置:
@Configuration
@EnableWebSecurity
public class DemoSecurityConfig extends WebSecurityConfigurerAdapter {
// add a reference to our security data source
@Autowired
@Qualifier("securityDataSource")
private DataSource securityDataSource;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(securityDataSource);
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
System.out.println("aplicando configuracion");
http.authorizeRequests()
.antMatchers("/employees/showForm*").hasAnyRole("MANAGER", "ADMIN")
.antMatchers("/employees/save*").hasAnyRole("MANAGER", "ADMIN")
.antMatchers("/employees/delete").hasRole("ADMIN")
.antMatchers("/employees/**").hasRole("EMPLOYEE")
.antMatchers("/resources/**").permitAll()
.antMatchers("/showMyLoginPage").permitAll()
.and()
.formLogin()
.loginPage("/showMyLoginPage")
.loginProcessingUrl("/authenticateTheUser")
.permitAll()
.and()
.logout().permitAll()
.and()
.exceptionHandling().accessDeniedPage("/access-denied");
}
}
配置:
@Configuration
@EnableJpaRepositories(basePackages={"${spring.data.jpa.repository.packages}"})
public class DemoDataSourceConfig {
@Primary
@Bean
@ConfigurationProperties(prefix="app.datasource")
public DataSource appDataSource() {
return DataSourceBuilder.create().build();
}
@Bean
@ConfigurationProperties(prefix="spring.data.jpa.entity")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder, DataSource appDataSource) {
return builder
.dataSource(appDataSource)
.build();
}
@Bean
@ConfigurationProperties(prefix="security.datasource")
public DataSource securityDataSource() {
return DataSourceBuilder.create().build();
}
}
提前感谢您的帮助。
【问题讨论】:
标签: java spring spring-boot spring-security