以下错误是我在做springboot整合shiro的过程中出现的错误,然后就在网络上到处搜集解决办法,花费了不少时间,我知识还不够充分,只是写一下错误的解决办法,至于更详细的缘由,还要去搜一搜大佬的回复。知识浅薄,如有错误,还请谅解。
1、错误:Autowired members must be defined in valid myrealm
解决:在MyRealm类的上方加入@component
2、错误:public DefaultShiroFilterChainDefinition shiroFilterChainDefinition()
{
}
其中DefaultShiroFilterChainDefinition爆红
解决:添加依赖
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.4.2</version>
</dependency>
即可解决
3、错误:Invalid value type for attribute 'factoryBeanObjectType': java.lang.String
经查阅,mybatis-plus的依赖有问题,应改为
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.7</version>
</dependency>
4、使用MD5Hash加密时,发现上面的依赖里没有 import org.apache.shiro.crypto.hash.Md5Hash;
,MD5Hash爆红
解决:shiro相关的依赖版本改为1.4.2就可以了,当时我用的版本是2.0.1
<dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> <version>1.4.2</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-web</artifactId> <version>1.4.2</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <version>1.4.2</version> </dependency>
5、错误:Invalid character found in method name报错
解决:https://localhost:8080/ 改为 http://localhost:8080/
6、报错信息org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration.、
解决:
在这行下面添加
ThreadContext.bind(defaultWebSecurityManager);
变成这样就可以解决,反正我的是解决了
7、java.lang.ClassNotFoundException: javax.servlet.ServletRequest
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
解决:添加 javax.servlet 的依赖
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
8、java.lang.IllegalStateException: No primary or single unique constructor found for interface javax.servlet.http.HttpSession
解决:// 将javax替换成 jakarta
将 import javax.servlet.http.HttpSession;修改为: import jakarta.servlet.http.HttpSession;