如何在 Spring 引导中创建 JDBC TokenStore?
How do you create JDBC TokenStore in Spring Boot?
我尝试按照此答案将 JDBC TokenStore 添加到我的应用程序。
正在使用 InMemoryTokenStore
。我需要知道将此代码放在哪里
@Bean(name = "OAuth")
@ConfigurationProperties(prefix="datasource.oauth")
public DataSource secondaryDataSource() {
return DataSourceBuilder.create().build();
}
我试着把它放在
@Configuration
@EnableAuthorizationServer
public class OAuth2Configuration extends AuthorizationServerConfigurerAdapter {
但是我得到了错误
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'OAuth2Configuration': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'OAuth': Requested bean is currently in creation: Is there an unresolvable circular reference?
所以我把它移到主class
@SpringBootApplication
@MapperScan("com.example.mapper")
public class ExampleApplication extends SpringBootServletInitializer {
但随后出现了不同的错误
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: The url cannot be null
那么我应该把那个片段放在哪里来定义 bean?
您需要在 application-{profile}.properties
中包含数据库配置属性,特别是它们需要以 datasource.oauth
为前缀。这里 profile
将是您的应用程序 运行 所在的任何配置文件(例如:dev、stage、prod)。
显示的错误清楚地表明在特定属性文件中没有 datasource.oauth.url=..
属性。
我尝试按照此答案将 JDBC TokenStore 添加到我的应用程序。
正在使用 InMemoryTokenStore
。我需要知道将此代码放在哪里
@Bean(name = "OAuth")
@ConfigurationProperties(prefix="datasource.oauth")
public DataSource secondaryDataSource() {
return DataSourceBuilder.create().build();
}
我试着把它放在
@Configuration
@EnableAuthorizationServer
public class OAuth2Configuration extends AuthorizationServerConfigurerAdapter {
但是我得到了错误
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'OAuth2Configuration': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'OAuth': Requested bean is currently in creation: Is there an unresolvable circular reference?
所以我把它移到主class
@SpringBootApplication
@MapperScan("com.example.mapper")
public class ExampleApplication extends SpringBootServletInitializer {
但随后出现了不同的错误
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: The url cannot be null
那么我应该把那个片段放在哪里来定义 bean?
您需要在 application-{profile}.properties
中包含数据库配置属性,特别是它们需要以 datasource.oauth
为前缀。这里 profile
将是您的应用程序 运行 所在的任何配置文件(例如:dev、stage、prod)。
显示的错误清楚地表明在特定属性文件中没有 datasource.oauth.url=..
属性。