java 在tomcat中显示Spring-security的SQL错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3736933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Show SQL errors of Spring-security in tomcat
提问by Mark Baijens
I got a web application using the spring-security framework. I setted up a database to store users and their roles, but tomcat gives the following error.
我得到了一个使用 spring-security 框架的 Web 应用程序。我建立了一个数据库来存储用户和他们的角色,但是 tomcat 给出了以下错误。
17-sep-2010 11:56:14 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
17-sep-2010 11:56:14 org.springframework.jdbc.support.SQLErrorCodesFactory <init>
INFO: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
Is there any way how i can see the errors that occurred? I couldn't find anything in the tomcat and mysql logs.
有什么办法可以查看发生的错误吗?我在 tomcat 和 mysql 日志中找不到任何内容。
Im using tomcat 7.0.2 and mysql 5.1
我使用的是 tomcat 7.0.2 和 mysql 5.1
Update:Added log4j.properties
更新:添加了 log4j.properties
log4j.rootLogger=warn, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.logger.org.springframework.security=DEBUG
# log4j.logger.org.springframework.target=System.out
and web.xml
和 web.xml
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
No succes yet
还没有成功
采纳答案by matt b
This message is not about an error occuring at runtime in your application:
此消息与应用程序运行时发生的错误无关:
INFO: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
rather this is simply the Spring framework's JDBC supportlogging the fact that it has loaded support for translating error codes native to each of these SQL databases which translate into Spring's DataAccessException hierarchy. No error has occurred in the log message here.
相反,这只是Spring 框架的 JDBC 支持记录了这样一个事实,即它已经加载了对转换这些 SQL 数据库中的每一个的本地错误代码的支持,这些错误代码转换为 Spring 的 DataAccessException 层次结构。此处的日志消息中没有发生错误。
If you want to be able to log more information about what Spring is doing, etc., the framework uses commons-loggingand there are a number of ways to configure the actual output.
如果您希望能够记录有关 Spring 正在做什么等的更多信息,该框架使用 commons-logging,并且有多种方法可以配置实际输出。
回答by Eragonz91
I was using in my spring security something like select * from USER ...
我在 Spring Security 中使用了类似 select * from USER ...
change for select * from user .. and it works
更改 select * from user .. 并且它有效
回答by chiranth
The reason i was getting the above error is due to the fact that i had missed 1 as enabledattribute in the first sql query and u.usernameattribute in the second sql query of the spring security config.
我收到上述错误的原因是因为我在 spring 安全配置的第一个 sql 查询和u.username属性的第二个 sql 查询中错过了1 as enabled属性。
<authentication-manager>
<authentication-provider>
<password-encoder hash="md5"/>
<jdbc-user-service
data-source-ref="dataSource"
users-by-username-query="select username, password, 1 as enabled from users where username = ?"
authorities-by-username-query="select u.username, ur.user_role from USERS u, USERS_ROLE ur where u.sl_no = ur.user_id and u.username = ?"/>
</authentication-provider>
</authentication-manager>
<b:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<b:property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<b:property name="url" value="jdbc:hsqldb:hsql://localhost/" />
<b:property name="username" value="SA" />
<b:property name="password" value="" />
</b:bean>
Hope this helps someone struggling with this error!!
希望这可以帮助那些在这个错误中挣扎的人!!

