Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8300483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:34:29+00:00 2026-06-08T16:34:29+00:00

I was just reading this article: http://www.tutorialized.com/view/tutorial/Spring-MVC-Application-Architecture/11986 which I find great. It explains the

  • 0

I was just reading this article:

http://www.tutorialized.com/view/tutorial/Spring-MVC-Application-Architecture/11986

which I find great. It explains the layer architecture nicely and I was glad that the architecture I’m working with pretty much is what he describes.

But there’s one thing, that I don’t seem to get:

First: what exactly is business logic and what is it not? In the article he says (and he’s not the only one), that business logic should go in the domain model. So an Account class should have an activate() method that knows how to activate an Account. In my understanding this would involve some persistence work probably. But the domain model should not have a dependency of DAOs. Only the service layer should know about DAOs.

So, is business logic just what a domain entity can do with itself? Like the activate()method would set the active property to true, plus set the dateActivated property to new Date() and then it’s the service’s task to first call account.activate()and second dao.saveAccount(account)? And what needs external dependencies goes to a service? That’s what I did until now mostly.

public AccountServiceImpl implements AccountService
{
  private AccountDAO dao;
  private MailSender mailSender;

  public void activateAccount(Account account)
  {
     account.setActive(true);
     account.setDateActivated(new Date());
     dao.saveAccount(account);
     sendActivationEmail(account);
  }
  private void sendActivationEmail(Account account)
  {
    ...
  }
}

This is in contrast to what he says, I think, no?

What I also don’t get is the example on how to have Spring wire domain objects like Account. Which would be needed should Account send its e-mail on its own.

Given this code:

import org.springframework.mail.MailSender;  
import org.springframework.mail.SimpleMailMessage;  

public class Account {  
   private String email;  
   private MailSender mailSender;  
   private boolean active = false;  

   public String getEmail() {  
      return email;  
   }  

   public void setEmail(String email) {  
      this.email = email;  
   }  

   public void setMailSender(MailSender mailSender) {  
      this.mailSender = mailSender;  
   }  

   public void activate() {  
      if (active) {  
      throw new IllegalStateException("Already active");  
      }  

      active = true;  
      sendActivationEmail();  
   }  

   private void sendActivationEmail() {  
      SimpleMailMessage msg = new SimpleMailMessage();  
      msg.setTo(email);  
      msg.setSubject("Congrats!");  
      msg.setText("You're the best.");  
      mailSender.send(msg);  
   }  
}

If I use Hibernate, I could use the DependencyInjectionInterceptorFactoryBean in order to wire mailSender. If I use JDBC instead, I’d really write the follwing cumbersome code? Plus, also when I create a new instance for Account in a MVC controller, for let’s say populating it to a model??

  BeanFactory beanFactory = new XmlBeanFactory(  
     new ClassPathResource("chapter3.xml"));  
  Account account = new Account();  
  account.setEmail("email@example.com");  
  ((AutowireCapableBeanFactory)beanFactory).applyBeanPropertyValues(  
        account, "accountPrototype");  
  account.activate(); 

This is not reliable and very cumbersome, no? I’d have to ask myself where that object has been created, whenever I see an instance of Account. Plus, if I would go with this approach: I have not a single appContext.xml I could pass, but several, one for persistence, one for the service config. How would I do that? Plus, that would create a completely new context every time such an instance is created or am I missing something?

Is there no better solution to that?

Any help is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:34:30+00:00Added an answer on June 8, 2026 at 4:34 pm

    I think send activation email action is not a part of a business-layer here, your domain logic here is the account activation action, that piece of logic should live in the DomainObject with name Account ( activate() method ). The send activation email action is the part of infrastructure or application layers.

    Service is the object that handles account activation request and connects business-layer and others. Service takes the given account, activates them and performs send activation email action of MailSenderService or something like this.

    Short sample:

    public AccountServiceImpl implements AccountService
    {
     private AccountDAO dao;
     private MailSenderService mailSender;
    
     public void activateAccount(AccountID accountID)
     {
       Account account = dao.findAccount(accountID);
       ....
       account.activate();
       dao.updateAccount(account);
       ....
    
       mailSender.sendActivationEmail(account);
     }
    
    }
    

    The next step that I can suggest is a complete separation of business layer
    and a layer of infrastructure. This can be obtained by introducing the
    business event. Service no longer has to perform an action to send an
    email, it creates event notifying other layers about
    account activation.

    In the Spring we have two tools to work with events, ApplicationEventPublisher and ApplicationListener.

    Short example, service that publish domain events:

    public AccountActivationEvent extends ApplicationEvent {
        private Account account;
    
        AccountActivationEvent(Account account) {
           this.account = account;
        }
    
        public Account getActivatedAccount() {
           return account;
        }
    }
    
    public AccountServiceImpl implements AccountService, ApplicationEventPublisherAware
    {
     private AccountDAO dao;
     private ApplicationEventPublisher epublisher;
    
     public void setApplicationEventPublisher(ApplicationEventPublisher epublisher) {
        this.epublisher = epublisher;
     }
    
     public void activateAccount(AccountID accountID)
     {
      Account account = dao.findAccount(accountID);
      ....
      account.activate();
      dao.updateAccount(account);
      ....
    
      epublisher.publishEvent(new AccountActivationEvent(account));
     }
    
    }
    

    And domain event listener, on the infrastructure layer:

    public class SendAccountActivationEmailEventListener 
          implements ApplicationListener<AccountActivationEvent> {
    
      private MailSenderService mailSender;
    
      .... 
    
      public final void onApplicationEvent(final AccountActivationEvent event) {
       Account account = event.getActivatedAccount():
        .... perform mail ...
       mailSender.sendEmail(email);
      }
     }
    

    Now you can add another activation types, logging, other infrastructure stuff support without change and pollute your domain(business)-layer.

    Ah, you can learn more about spring events in the documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just finished reading Mike's awesome tutorial over at: http://www.mikesdotnetting.com/Article/150/Web-Pages-Efficient-Paging-Without-The-WebGrid and I am using
just was reading this article http://highscalability.com/blog/2010/3/23/digg-4000-performance-increase-by-sorting-in-php-rather-than.html And found this nice article http://wiki.apache.org/cassandra/DataModel I just
Just finished reading this blog post: http://www.skorks.com/2010/03/an-interview-question-that-prints-out-its-own-source-code-in-ruby/ In it, the author argues the case
I was reading this: http://www.openfeint.com/ofdeveloper/index.php/kb/article/000089 , and it seemed to make out that the
I was reading this article: http://www.devarticles.com/c/a/PHP/Creating-a-Membership-System/2/ I am not sure if I understand sessions
I'm reading this article http://www.codeguru.com/Csharp/.NET/net_security/authentication/article.php/c7415/ I still don't understand the concept of Principal (why
I was reading this article: http://sqlserverpedia.com/wiki/Understanding_the_StackOverflow_Database_Schema and the writer wrote something special about the
On this article: http://java.sun.com/developer/technicalArticles/tools/JavaSpaces/ is a tutorial how to run JavaSpaces client. I wrote
I've been reading this: http://www.thebuzzmedia.com/designing-a-secure-rest-api-without-oauth-authentication/ It's been a really great article. One problem I'm
I was just reading this article and it mentions that some organization had an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.