[英]Spring boot + spring boot security start error
I'm doing a MVC project with spring boot and spring security and jsp.我正在做一个带有 spring 引导和 spring 安全性和 jsp 的 MVC 项目。 I'm just training my spring and I have the same project running without spring boot.
我只是在训练我的 spring 并且在没有 spring 引导的情况下运行相同的项目。 Currently I moved to springboot and when I try to start I get:
目前我搬到了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: Root WebApplicationContext: initialization completed in 6813 ms 2020-05-09 17:28:38.753 WARN 21308 --- [ restartedMain] ConfigServletWebServerApplicationContext: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inMemoryDatabaseShutdownExecutor' defined in class path resource [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class]: Unsatisfied dependency expressed through method 'inMemoryDatabaseShutdownExecutor' param
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 创建错误eter 0;
0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed;
嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为“dataSource”的 bean 时出错; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception;
嵌套异常是 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: Stopping service [Tomcat] 2020-05-09 17:28:38.826 INFO 21308 --- [ restartedMain] ConditionEvaluationReportLoggingListener:
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:
*************************** APPLICATION FAILED TO START
****************************** 应用程序无法启动
Description:
描述:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
无法配置数据源:未指定“url”属性,并且无法配置嵌入式数据源。
Reason: Failed to determine a suitable driver class
原因:无法确定合适的驱动程序 class
I have no idea what is happening.我不知道发生了什么。
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:配置:
@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:配置:
@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();
}
}
Thanks for your help in advance.提前感谢您的帮助。
In your properties file...在您的属性文件中...
Change app.datasource.*
to spring.datasource.*
like below..将
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
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
无法配置数据源:未指定“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 require any url
/ username
/ password
only the dependency is enough. 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
,只要依赖就足够了。
In your case, it's not embedded database.. so the property name spring looks for, must be provided correctly.在您的情况下,它不是嵌入式数据库。因此,必须正确提供要查找的属性名称 spring。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.