Java AspectJ导致sessionfactory为空?
每当我在SpringHibernate项目中使用aspect并放置@EnableJautProxy时,sessionfactory都是空的。否则一切正常 我得到sessionfactory的空指针异常。一旦我删除它的应用程序的工作,但方面不工作 请帮帮我Java AspectJ导致sessionfactory为空?,java,spring,hibernate,aop,Java,Spring,Hibernate,Aop,每当我在SpringHibernate项目中使用aspect并放置@EnableJautProxy时,sessionfactory都是空的。否则一切正常 我得到sessionfactory的空指针异常。一旦我删除它的应用程序的工作,但方面不工作 请帮帮我 @Aspect @Component public class AspectHandler { @Pointcut("within(com.x.y..*)") private void
@Aspect
@Component
public class AspectHandler {
@Pointcut("within(com.x.y..*)")
private void selectAll() {
}
@Before("selectAll()")
public void beforeAdvice() throws Throwable {
System.out.println("before method exceution");
}
@Around("selectAll()")
public void aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable{
System.out.println("firing aspect");
Object retVal = joinPoint.proceed();
System.out.println("retval" +retVal);
}
}
学生指南
@Repository
public class StudentDAOImpl implements StudentDAO{
@Autowired
private SessionFactory sessionFactory;
@Override
public Student getStudent(int rollNo) {
String query = "from Student where rollNo = "+rollNo;
Session session = sessionFactory.getCurrentSession();
List<Student> students = session.createQuery(query).list();
if(students != null && students.size()==1)
{
return students.get(0);
}
return null;
}
@Override
public List<Student> getStudents() {
String query = "from Student";
Session session = sessionFactory.getCurrentSession();
List<Student> students = session.createQuery(query).list();
return students;
}
}
@存储库
公共类StudentDAOImpl实现StudentDAO{
@自动连线
私人会话工厂会话工厂;
@凌驾
公立学生getStudent(int rollNo){
String query=“from Student where rollNo=“+rollNo;
Session Session=sessionFactory.getCurrentSession();
List students=session.createQuery(query.List();
if(students!=null&&students.size()=1)
{
返回学生。获取(0);
}
返回null;
}
@凌驾
公众学生名单{
String query=“from Student”;
Session Session=sessionFactory.getCurrentSession();
List students=session.createQuery(query.List();
留学生;
}
}
堆栈跟踪: HTTP错误500
Server Error</pre></p><h3>Caused by:</h3><pre>java.lang.NullPointerException
at com.x.y.resources.school.dao.SchoolDAOImpl.getSchoolDetails(SchoolDAOImpl.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocati on.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java: 157)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedin gJoinPoint.java:85)
at com.x.y.config.aop.AspectHandler.aroundAdvice(AspectHandler.java:40)
at
服务器错误原因:java.lang.NullPointerException
请访问com.x.y.resources.school.dao.SchoolDAOImpl.getSchoolDetails(SchoolDAOImpl.java:30)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
位于java.lang.reflect.Method.invoke(Method.java:483)
位于org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
位于org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocati on.java:190)
在org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:157)上
位于org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
在org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:179)上
在org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.procedure(methodinvocationproceedingjjoinpoint.java:85)
位于com.x.y.config.aop.AspectHandler.aroundAdvice(AspectHandler.java:40)
在
请张贴stacktrace。但我假设这是因为您没有@Before(“execution…”),根据您正在执行的方面的类型(发布您的方面),以及如何使用@Autowired
或调用setSessionFactory
将会话工厂设置到bean上?我怀疑有一个错误的@Around
方面。我已经发布了stacktrace…我无法在sessionfactory中重现错误,因为它在加载主页时也会抛出错误。你也可以发布SchoolDAOImpl
代码吗?错误在AOPHandler中,位于com.x.y.config.aop.AspectHandler.aroundAdvice(AspectHandler.java:40)张贴于
Server Error</pre></p><h3>Caused by:</h3><pre>java.lang.NullPointerException
at com.x.y.resources.school.dao.SchoolDAOImpl.getSchoolDetails(SchoolDAOImpl.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocati on.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java: 157)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedin gJoinPoint.java:85)
at com.x.y.config.aop.AspectHandler.aroundAdvice(AspectHandler.java:40)
at