在閱讀這一章的時候,基本沒有什麼障礙,但是有一個地方文章是寫錯了。
在Create DAO Interface 那一節中“Go to src > add package named au.com.tusc.dao > Add a class StoreAcessDAOImpl in that package”紅色字型錯了,應該是StoreAccessDAOImpl。
還有就是因為使用不同版本的jboss和lomboz,所以文章中說到的ejbGenerate.xml 檔案對應的是xdoclet.xml檔案。
Stateless Session Bean
根據Mastering EJB 2nd的描述,建立一個EJB Component所需要的幾個步驟
1. Write the .java files that compose your bean: the component interfaces,
home interfaces, enterprise bean class file, and any helper classes you
might need.這一步因為有lomboz的幫忙,我只需要寫enterprise bean class檔案,在這一章的例子當中就是StoreAccessBean就是enterprise bean檔案。然後在這個檔案的開始地方加幾個tag,如@ejb.dao,lomboz就會自動產生StoreAccessDAO檔案。
2. Write the deployment descriptor. Lomboz會自動建立相關的部署檔案
3. Compile the .java files from step 1 into .class files.Writing Your First Bean
4. Using the jar utility, create an Ejb-jar file containing the deploymentdescriptor and .class files.
5. Deploy the Ejb-jar file into your container in a vendor-specific manner,perhaps by running a vendor-specific tool or perhaps by copying yourEjb-jar file into a folder where your container looks to load Ejb-jar files.
6. Configure your EJB server so that it is properly configured to host yourEjb-jar file. You might tune things such as database connections, thread pools, and so on. This step is vendor-specific and might be done through a
Web-based console or by editing a configuration file.
7. Start your EJB container and confirm that it has loaded your Ejb-jar file.
8. Optionally, write a standalone test client .java file. Compile that test client into a .class file. Run the test client from the command line and have it exercise your bean’s APIs.
3~8步lomboz會自動幫我完成。看來有了Lomboz真的可以把精力集中在商務邏輯的開發。
不過在實現這個例子的時候,一個部署ejb的典型錯誤又發生了,就是tag語句寫錯了,這些東西都是只有在部署後才可以知道,不可以編譯來校正,而且出了錯也不容易找,真是麻煩。唯一的辦法就是開啟lomboz的文檔,然後複製粘貼,希望這樣會少一點錯誤。或者等我找到更加先進的工具進行校正,暫時就只好這樣子了。