【发布时间】:2018-05-10 19:40:01
【问题描述】:
运行测试时出现以下错误。我不明白这一点,因为我是 shiro 的新手。请帮助我
enter code herejava.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:534)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:195)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:241)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.apache.shiro.config.ConfigurationException: Unable to instantiate class [javax.sql.DataSource] for object named 'ds'. Please ensure you've specified the fully qualified class name correctly.
at org.apache.shiro.config.ReflectionBuilder.createNewInstance(ReflectionBuilder.java:151)
at org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:119)
at org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:161)
at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:124)
at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:102)
at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:88)
at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:46)
at org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:123)
at com.advi.test.shiro.TestShiro.<clinit>(TestShiro.java:23)
... 22 more
Caused by: org.apache.shiro.util.InstantiationException: Unable to instantiate class [javax.sql.DataSource]
at org.apache.shiro.util.ClassUtils.newInstance(ClassUtils.java:179)
at org.apache.shiro.util.ClassUtils.newInstance(ClassUtils.java:164)
at org.apache.shiro.config.ReflectionBuilder.createNewInstance(ReflectionBuilder.java:144)
... 30 more
Caused by: java.lang.InstantiationException: javax.sql.DataSource
at java.lang.Class.newInstance(Class.java:359)
at org.apache.shiro.util.ClassUtils.newInstance(ClassUtils.java:177)
... 32 more
这是 shiro.ini 文件。请告诉我我犯了什么错误
#myRealm = MyRealm
#myRealm.credentialsMatcher = $myRealmCredentialsMatcher
ps = org.apache.shiro.authc.credential.DefaultPasswordService
pm = org.apache.shiro.authc.credential.PasswordMatcher
pm.passwordService = $ps
aa = org.apache.shiro.authc.credential.AllowAllCredentialsMatcher
sm = org.apache.shiro.authc.credential.SimpleCredentialsMatcher
#jof = org.apache.shiro.jndi.JndiObjectFactory
#jof.resourceName = jdbc/UserDB
#jof.requiredType = javax.sql.DataSource
#jof.resourceRef = true
#; Note factories are automatically invoked via getInstance(),
#; see org.apache.shiro.authc.config.ReflectionBuilder::resolveReference
#jdbcRealm.dataSource = $jof
ds = javax.sql.DataSource
ds.url = jdbc:mysql://192.168.1.111:3306/Test
ds.user = dbuser
ds.password = dbuser
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
#realm.permissionsLookupEnabled = true
jdbcRealm.credentialsMatcher = $pm
jdbcRealm.dataSource = $ds
securityManager.realms = $jdbcRealm
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
#ds = javax.sql.DataSource
#ds.url = jdbc:mysql://192.168.1.111:3306/Test
#ds.user = dbuser
#ds.password = dbuser
#jdbcRealm.dataSource = $ds
# Configure JDBC realm SQL queries.
jdbcRealm.authenticationQuery = select pass from users where name = ?;
sha256Matcher = org.apache.shiro.authc.credential.HashedCredentialsMatcher
sha256Matcher.hashAlgorithmName=SHA-256
# enable matcher in iniRealm (object responsible for authentication)
iniRealm.credentialsMatcher = $sha256Matcher
它说它无法启动 java.sql.datasource..我应该怎么做才能启动它
【问题讨论】: