2015-02-04 4 views
0

도움말! 나는 봄 + 최대 절전 모드를 사용하고 있는데 나는이 같은 AOP를 사용하려고 해요 :봄 최대 절전 모드 + AOP

package ua.i.pustovalov.table; 
enter code here 

@Aspect 
public class Aoprad { 

    @Pointcut("execution(* *getAll(..))") 
    public void performance() { 
    } 

    public Aoprad() { 

    } 

    @Around("performance()") 
    public void AfterAndPriv(ProceedingJoinPoint joinPoint) { 
    try { 

     System.out.println("Open query"); 
     joinPoint.proceed(); 
     System.out.println("Close query"); 
    } catch (Throwable e) { 
     e.printStackTrace(); 
    } 

    } 

} 

내 방법을 사용하려고하면, 그것은 null를 돌려줍니다.

public class TestDao { 

public static void main(String[] args) { 
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
    new String[] { "applicationContext.xml" }, true); 

DaoInterface das = (DaoInterface) context.getBean("dataDao"); 

System.out.println(das.getAll()); 

} 

<context:annotation-config /> 

<aop:aspectj-autoproxy /> 
<context:component-scan base-package="ua.i.pustovalov.*"> 
</context:component-scan> 





<bean id="audience" class="ua.i.pustovalov.table.Aoprad" /> 


<aop:config> 
    <aop:pointcut id="myPointcut" 
     expression="execution(* ua.i.pustovalov.maven.*.*(..))" /> 
    <aop:advisor advice-ref="txAdvice" pointcut-ref="myPointcut" /> 
</aop:config> 



<tx:advice id="txAdvice" transaction-manager="transactionManager"> 
    <tx:attributes> 
     <!-- <tx:method name="get*" propagation="REQUIRED" read-only="true" /> --> 
     <tx:method name="getAll*" propagation="REQUIRED" read-only="true" /> 

    </tx:attributes> 
</tx:advice> 
<bean id="transactionManager" 
    class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 

<bean id="dataSource" 
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <property name="driverClassName"> 
     <value>com.mysql.jdbc.Driver</value> 
    </property> 
    <property name="url"> 
     <value>jdbc:mysql://localhost:3306/homebase</value> 
    </property> 
    <property name="username"> 
     <value>root</value> 
    </property> 
    <property name="password"> 
     <value></value> 
    </property> 
</bean> 

<bean id="sessionFactory" 
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
    <property name="dataSource" ref="dataSource" /> 
    <property name="configLocation" value="classpath:/hibernate.cfg.xml" /> 
    <property name="hibernateProperties"> 
     <props> 
      <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 
      <prop key="hibernate.show_sql">true</prop> 
      <prop key="hibernate.current_session_context_class">thread</prop> 
      <!-- <prop key="hibernate.hbm2ddl.auto">create</prop> --> 
     </props> 
    </property> 
</bean> 

<bean id="dataDao" class="ua.i.putsovalov.dao.DaoStudent"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 

내 DAO 클래스

package ua.i.putsovalov.dao; 

public class DaoStudent extends HibernateDaoSupport implements DaoInterface { 

public DaoStudent() { 
} 

@Override 
protected HibernateTemplate createHibernateTemplate(
    SessionFactory sessionFactory) { 
HibernateTemplate result = super 
    .createHibernateTemplate(sessionFactory); 
result.setAllowCreate(true); 
return result; 
} 

@Override 
public Student get(int id) { 

return (Student) getSession().get(Student.class, id); 
} 

@Override 
public Student get(String text) { 
return (Student) getSession().get(Student.class, text); 
} 

@SuppressWarnings("unchecked") 
@Override 
public Collection<Student> getAll() { 
return getSession().createCriteria(Student.class).list(); 
} 

} 

그리고 인터페이스 나는이 문제를 디버깅하기 위해 취할 수있는 어떤 단계를

public interface DaoInterface { 

Student get(int id); 

Student get(String text); 

Collection<Student> getAll(); 
} 

?

+0

스택 오버 플로우에 오신 것을 환영합니다! 해결하려는 문제가 무엇인지는 분명하지 않습니다. 'das.getAll()'은'null'을 리턴하고 있습니까? 오류가 있습니까? –

+0

오류가 발생했습니다! 유무 <- 열기 quary 최대 절전 모드 : id0_0_로 this_.mark mark0_0_로, this_.name name0_0_로, this_.surname listofstudent에서 surname0_0_로 this_ 닫기 quary 널 (null)을 this_.id 선택 -> –

+0

오류는 DaoStudent 클래스의 getAll() 함수가 null을 반환하고 체크 데이터가 listofstudent 테이블에 있음을 나타냅니다. – Basavaraj

답변

0

around 애스펙트를 사용하는 경우 void이 아닌 Object을 반환하는 메서드 시그니처를 항상 사용해야하며 항상 proceed() 메서드 호출 결과를 반환해야합니다. 그렇게하지 않으면,이 aspect에 의한 어드바이스 인 모든 메소드는 아무것도 돌려주지 않기 때문에 null를 돌려줍니다.

@Around("performance()") 
public Object AfterAndPriv(ProceedingJoinPoint joinPoint) { 
try { 
    System.out.println("Open query"); 
    return joinPoint.proceed(); 
} catch (Throwable e) { 
    e.printStackTrace(); 
} finally { 
    System.out.println("Close query"); 
} 
} 
+0

감사합니다. 이제는 괜찮습니다. –

관련 문제