DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Data Annotation's Essential Role in Machine Learning Success
  • Unraveling Lombok's Code Design Pitfalls: Exploring Encapsulation Issues
  • Automate Migration Assessment With XML Linter
  • Validate XML Request Against XML Schema in Mule 4

Trending

  • Revolutionizing Software Testing
  • Docker and Kubernetes Transforming Modern Deployment
  • Spring WebFlux Retries
  • REST vs. Message Brokers: Choosing the Right Communication
  1. DZone
  2. Coding
  3. Languages
  4. Moving from Spring's XML to Annotations in AppFuse

Moving from Spring's XML to Annotations in AppFuse

Matt Raible user avatar by
Matt Raible
·
Nov. 05, 08 · Interview
Like (0)
Save
Tweet
Share
16.15K Views

Join the DZone community and get the full member experience.

Join For Free

last night, i did a spike on appfuse to change xml to spring annotations (@repository, @service and @autowired) in its service and data modules. while i was able to accomplish everything in a few hours (including converting tests), i did run into a couple issues.

abstracttransactionaljunit4..tests vs. abstracttransactionaldatasource..tests

i've switched from my favorite spring class to the annotation-happy abstracttransactionaljunit4springcontexttests . however, this has presented an issue: when using atdssct, i was able to call endtransaction() and startnewtransaction() . with atj4sct, this doesn't seem possible. below is a screenshot of the diff on a test method in the jpa implementation of userdaotest:

abstracttransactionaljunit4springcontexttests vs. abstracttransactionaldatasourcespringcontexttests

on the right, you'll notice that i had to comment out @expectedexception to get the test to pass. this concerns me since this exception should be thrown. is there a way to call endtransaction() and startnewtransaction() when subclassing abstracttransactionaljunit4springcontexttests?

instantiating genericdao implementations programmatically


the second feature i tried to add is the ability to instantiate a genericdao programatically rather than requiring a xml bean definition. in current versions of appfuse, you can use the following bean definition to create a genericdao for a model object.

<bean id="persondao" class="org.appfuse.dao.hibernate.genericdaohibernate">
    <constructor-arg value="org.appfuse.tutorial.model.person"/> 
    <property name="sessionfactory" ref="sessionfactory"/>
</bean> 

when moving to a no-xml required architecture, it'd be nice to allow users to create genericdao's programmatically. below is the easiest way i've found to do this in a test:

genericdao<user, long> genericdao;
@autowired
sessionfactory sessionfactory;

@before
public void setup() {
    genericdao = new genericdaohibernate<user, long>(user.class);
    genericdao.setsessionfactory(sessionfactory);
}

however, there's a couple problems with this. first of all, mixing constructor injection and setter injection probably isn't a good idea. changing the constructor to take a sessionfactory solves this problem, but now all subclasses need to have a more verbose constructor:

@autowired
public userdaohibernate(sessionfactory sessionfactory) {
    super(user.class, sessionfactory);
}

whereas before they had:

public userdaohibernate() {
    super(user.class);
}

in an ideal world, i could call new genericdaohibernate<user, long>(user.class) and the sessionfactory would be wired in auto-magically. is this possible with spring 2.5?

the 2nd problem this presents is your client code will now be dependent on an implementation rather than the interface. i don't know how to solve that one, but i'd love to figure out a way to create genericdaos with no xml and no implementation details in the client. any ideas are most welcome.

if you'd like to see all the changes i made in converting from xml to annotations, please see this patch .

from http://raibledesigns.com/rd/entry/moving_from_spring_s_xml

XML Annotation AppFuse

Opinions expressed by DZone contributors are their own.

Related

  • Data Annotation's Essential Role in Machine Learning Success
  • Unraveling Lombok's Code Design Pitfalls: Exploring Encapsulation Issues
  • Automate Migration Assessment With XML Linter
  • Validate XML Request Against XML Schema in Mule 4

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: