application.properties 中的 Spring.queries 属性

标签 spring spring-boot spring-security

我有一个使用 Spring Security 进行身份验证和授权的 Web 应用程序。

在我的 securityConfiguration 文件中,我有这些行

@Autowired
private DataSource dataSource;

@Value("${spring.queries.users-query}")
private String usersQuery;

@Value("${spring.queries.roles-query}")
private String rolesQuery;

稍后用于身份验证。
在 application.properties 文件中,我有:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.jpa.show-sql= true

spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1


spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false


spring.queries.users-query=select email, password from users where email=?
spring.queries.roles-query=select u.email, r.role from users u inner join 
user_role ur on(u.user_id=ur.user_id) inner join role r 
on(ur.role_id=r.role_id) where u.email=?

但我得到:'spring.datasource.testWhileIdle' 是一个未知的属性。你的意思是“spring.datasource.tomcat.abandon-when-percentage-full”?
还有一个关于 spring.validationQuery 以及 spring.queries 的错误......它是黄色下划线。
所以登录过程总是返回false。

谁能帮我找出问题出在哪里?我是 Spring 框架的新手,任何帮助将不胜感激。

最佳答案

假设您使用的是连接池数据库请更改

spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1

对此:
spring.datasource.tomcat.test-while-idle=true
spring.datasource.tomcat.validation-query=SELECT 1

您可以在 Spring Documentation - Working with Database. 中查看更多相关信息。

也改spring.queries.users-queryspring.queries.roles-querymyapp.queries.users-querymyapp.queries.roles-query分别。所有以 spring.* 开头的属性是标准属性,所有可用的标准属性都列在 Spring Documentation 中.如果您需要使用自定义属性更改名称,例如使用 myapp.mycustomproperty

关于application.properties 中的 Spring.queries 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45901031/

相关文章:

spring-security - Spring security 有 SimpleGrantedAuthority 但 hasRole 不起作用

Spring Security 2.0 Facebook 连接

java - 如何为多个数据源创建/配置 Spring Actuator?

java - 在 Tomcat 中部署了 war 的 Hotswap Spring 应用程序

spring-boot - 无法从同一域中的另一台电脑访问 swagger ui

spring - 无法实例化 LoginUrlAuthenticationEntryPoint : No default constructor found

java - spring 引用文档中的 C 命名空间部分

javascript - AngularJS FileUpload 中未定义内容类型的用途

java - 如何在 REST Spring 中正确处理具有相互对象引用的请求主体?

spring - OAuth2RestTemplate 承载 token 类型