JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Web Framework  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 使用struts2 & spring +jdo但dao沒有注入請各位大大給小弟協助
stack





發文: 49
積分: 0
於 2010-08-09 22:38 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
各位大大
小弟在學習使用struts2 +spring+jdo
但在使用dao的時候一直出現
java.lang.NullPointerException
at youtube.action.TestAction.execute(TestAction.java:13)

1
2
3
4
5
6
7
8
public calss TestAction{
    private TestDao testDao;
    private List<Test> tests;
    public String execute()throws Exception{
        tests=testDao.findAll();
    }
}
 


1
2
3
4
5
6
public class TestDaoImp extends JdoDaoSupport implements TestDao{
    public List<Test> findAll(){
        return result;
    }
}
 


1
2
3
4
5
6
7
8
public calss TestAction{
    private TestDao testDao;
    private List<Test> tests;
    public String execute()throws Exception{
        tests=testDao.findAll();
    }
}
 


applicationContext.xml設定
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="byName"
  xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
 
   
  <bean id="persistenceManagerFactory"
    class="org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean">
    <property name="persistenceManagerFactoryName" value="transactions-optional" />
  </bean>
  
  <bean id="transactionManager" class="org.springframework.orm.jdo.JdoTransactionManager">
    <property name="persistenceManagerFactory" ref="persistenceManagerFactory" />
  </bean>
 
  <aop:config proxy-target-class="true">
    <aop:advisor pointcut="execution(* youtube.dao.*.*(..))"
      advice-ref="txAdvice" />
  </aop:config>
  <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
      <tx:method name="*" propagation="REQUIRED" />
    </tx:attributes>
  </tx:advice>
  
        <bean id="testDao" class="youtube.dao.TestDaoImp" scope="singleton"/>
 
  <bean id="TestAction" scope="prototype" class="youtube.action.TestAction">
        <constructor-arg ref="testDao" />
        </bean>
 
</beans>
 


stack edited on 2010-08-09 22:42
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
745 使用struts2 & spring +jdo但dao沒有注入請各位大大給小弟協助 stack 2370 2010-08-09 22:38
» JWorld@TW »  Web Framework

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8