Tag - java

java hibernate    2017-07-19 23:47:47    1260

因为我使用的是hibernate的注解配置,错误出在使用ManyToOne并进行级联查询的时候,我的注解配置是这样的

@ManyToOne(fetch = FetchType.LAZY,cascade=CascadeType.ALL)

原因是因为FetchType.LAZY相当于配置文件中的lazy设置为true,

解决办法就是改为

@ManyToOne(fetch = FetchType.EAGER,cascade=CascadeType.ALL)


在使用配置文件的时候也是会出现这个错误的,具体修改方式雷同,即把lazy设置为false

 


 

by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(防止爬虫):http://blog.liuyingguang.cn
OpenBI问答社区:http://openbi.liuyingguang.cn/

java shiro    2017-07-19 23:47:07    1396

关于shiro错误的分析
错误提示:

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.


错误原因:

在web.xml中配置shiro filter的时候,shiro filter放置位置放到了struts2 filter后面


原因分析:

如果使用struts2,那么在struts2加载静态资源的时候,需要将静态资源SecurityUtils也加载进去,如果将shiro filter放置位置放到了struts2 filter后面,那么必将导致无法加载到struts2中去,而后使用SecurityUtils.getSubject();的时候,导致出错,


解决办法:

shiro的filter应该放在struts2的 filter的上面

还可以在使用之前使用这种方式:即在SecurityUtils.getSubject();之前加入如下代码

 

Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
// 创建SecurityManager (根据配置创建SecurityManager实例)
SecurityManager security = factory.getInstance();
SecurityUtils.setSecurityManager(security);

这个想必不用解释了吧

 

 


 

by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(防止爬虫):http://blog.liuyingguang.cn
OpenBI问答社区:http://openbi.liuyingguang.cn/

java shiro    2017-07-19 23:45:15    1098

org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token [org.apache.shiro.authc.UsernamePasswordToken - **, rememberMe=false] did not match the expected credentials.

shiro在实现登陆认证的时候,一般从前端传来的是明文密码,而我们库中存放的是hash值,于是我们就需要转换下user的密码,

当然,我们有可能会在使用验证查询的时候,将user的密码转换成hash,然而在loginAction中,存放的user中的密码仍为明文,此时会出现错误

解决办法,在loginAction获取到pwd后,将其替换为hash,然后认证成功后存放到session中就ok了

 

user.setPwd(MD5Util.md5(user.getPwd())); 

 

by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(防止爬虫):http://blog.liuyingguang.cn
OpenBI问答社区:http://openbi.liuyingguang.cn/

java jetty web容器    2017-07-19 23:32:47    802
1、准备好一个非常简单点的web项目(maven项目)
2、准备好maven环境,并配置pom文件,关于jetty内容如下:
<!-- jetty dependecies begin -->
  <dependency>
   <groupId>org.eclipse.jetty</groupId>
   <artifactId>jetty-server</artifactId>
   <version>9.1.4.v20140401</version>
  </dependency>

  <dependency>
   <groupId>org.eclipse.jetty</groupId>
   <artifactId>jetty-webapp</artifactId>
   <version>9.1.4.v20140401</version>
  </dependency>

  <dependency>
   <groupId>org.eclipse.jetty</groupId>
   <artifactId>jetty-continuation</artifactId>
   <version>9.1.4.v20140401</version>
  </dependency>

  <dependency>
   <groupId>org.eclipse.jetty</groupId>
   <artifactId>jetty-jsp</artifactId>
   <version>9.1.4.v20140401</version>
  </dependency>
  <!-- jetty dependecies end -->

3、使用eclipse对maven项目进行build,获取build后的项目目录(或者将项目达成war包)

4、创建运行配置jetty的Server类
    运行war包的类
public class WebAppWarServer {
 public static void main(String[] args) throws Exception {
  Server server = new Server(8080);

  WebAppContext context = new WebAppContext();
  contex
jetty servlet java    2017-07-19 23:31:53    1467
错误原因:jetty 的版本和servlet—api版本不同,加载时的顺序不同,先加载servlet-api,而造成的错误。
解决方案:
1、如果是使用的是maven的话,在pom文件中,将jetty的jar包的依赖放在servlet-api的依赖前面
2、如果没有使用maven的话,可以在java build bath->order and export 将jetty的包上移                


完整报错日志:

2014-09-15 01:49:15.572:WARN:oejs.ServletHandler:qtp968838231-22: Error for /myapp/index.jsp
java.lang.NoSuchMethodError: javax.servlet.ServletContext.getJspConfigDescriptor()Ljavax/servlet/descriptor/JspConfigDescriptor;
 at org.apache.jasper.compiler.JspConfig.processWebDotXml(JspConfig.java:106)
 at org.apache.jasper.compiler.JspConfig.init(JspConfig.java:196)
 at org.apache.jasper.compiler.JspConfig.findJspProperty(JspConfig.java:259)
 at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:166)
 at org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
 at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:625)
 at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
 at org.apache.jasper.servlet.JspServlet.serviceJ
1/7