[英]Spring boot + spring boot security start error
我正在做一个带有 spring 引导和 spring 安全性和 jsp 的 MVC 项目。 我只是在训练我的 spring 并且在没有 spring 引导的情况下运行相同的项目。 目前我搬到了springboot,当我尝试开始时,我得到:
2020-05-09 17:28:38.521 INFO 21308 --- [ restartedMain] oac.c.C.[Tomcat].[localhost].[/]: Initializing Spring embedded WebApplicationContext 2020-05-09 17:28:38.527 INFO 21308 --- [restartedMain] osweb.context.ContextLoader:根 WebApplicationContext:初始化在 6813 毫秒内完成 2020-05-09 17:28:38.753 WARN 21308 --- [restartedMain] ConfigServletWebServerApplicationContext:在上下文初始化期间遇到异常尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:在 class 路径资源 [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class] 中定义的名称为“inMemoryDatabaseShutdownExecutor”的 bean 创建错误 0; 嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为“dataSource”的 bean 时出错; 嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [com.zaxxer.hikari.HikariDataSource]:工厂方法 'dataSource' 抛出异常; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class 2020-05-09 17:28:38.769 INFO 21308 --- [ restartedMain] o.apache.catalina.core. StandardService:停止服务 [Tomcat] 2020-05-09 17:28:38.826 INFO 21308 --- [restartedMain] ConditionEvaluationReportLoggingListener:
****************************** 应用程序无法启动
描述:
无法配置数据源:未指定“url”属性,并且无法配置嵌入式数据源。
原因:无法确定合适的驱动程序 class
我不知道发生了什么。
应用程序属性
# 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();
}
}
提前感谢您的帮助。
在您的属性文件中...
将app.datasource.*
更改为spring.datasource.*
如下所示..
# JDBC properties
#
spring.datasource.url=jdbc:mysql://localhost:3306/web_customer_tracker?useSSL=false&serverTimezone=UTC
spring.datasource.username=springstudent
spring.datasource.password=springstudent
无法配置数据源:未指定“url”属性,并且无法配置嵌入式数据源。
This error message gives hint that when Soring looks for database URL property.. (they have a fixed property name for it.. like spring.datasource.*
) Or Else.. if you are using any embedded database like DB2 then it does not需要任何url
/ username
/ password
,只要依赖就足够了。
在您的情况下,它不是嵌入式数据库。因此,必须正确提供要查找的属性名称 spring。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.