Announcement Announcement Module
Collapse
No announcement yet.
applicationContext.xml validation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • applicationContext.xml validation

    Earlier I made a mistake and forgot to add a property of a bean and called this property in a OO way.

    As following:
    <bean id="authManager" class="service.AuthManager">
    <property name="logInBean"><ref bean="logInBean"/></property>
    </bean>

    And in the class of authManger, I did:
    public class AuthManager implementes BusinessManager {
    protected LogInBeanBean logInBean;
    private LogInPersistenceService logInPersistenceService;

    //setters of both attributes ....

    public boolean authentication (HttpSession session)
    {
    ......
    LogInPersistenceService logInPersistenceService= new LogInPersistenceService ();
    logInPersistenceService.doSometh();


    Everything compiled and started without any problem, I just couldn't get the correct result. I solved this problem eventually. However, I just wonder if spring framework provides a way of validation that could help to identify this kind of mistakes?

    Thanks,

    Jin

  • #2
    InitializingBean

    Hi Jin,

    If your bean implements the InitializingBean interface, you can determine whether the required properties were set. For instance:

    Code:
    public class AuthManager implementes BusinessManager, InitializingBean {
       
       protected LogInBeanBean logInBean;
       private LogInPersistenceService logInPersistenceService;
    
       public void afterPropertiesSet() throws IllegalArgumentException, BeanInitializationException {
          if (this.logInBean == null) {
             throw new IllegalArgumentException("logInBean cannot be null");
          }
          if (this.logInPersistenceService== null) {
             throw new IllegalArgumentException("logInPersistenceService cannot be null");
          }
       }
    
       //setters of both attributes ....
    
       public boolean authentication (HttpSession session) {
    
          LogInPersistenceService logInPersistenceService= new LogInPersistenceService ();
          logInPersistenceService.doSometh();
    
       }
    
    }
    Hope this helps!

    -Arthur Loder

    Comment


    • #3
      Thank you, that helps!

      Jin

      Comment


      • #4
        Hi, Arthur:

        Just wondering, if there is any other way, such as some attribute can be configured in xml file to approach the same result. Otherwise, we have to write the same set of code over and over again in all the beans registered in configuration file(s).

        Thank you,

        Jin

        Comment


        • #5
          Relevant Link

          Hi Jin,

          Check out this link.

          Also pay attention to the comments section and this Jira Issue.

          -Arthur Loder
          Last edited by Arthur Loder; Oct 25th, 2006, 05:22 PM. Reason: Added additional info

          Comment


          • #6
            beandoc helps

            I'd also recommend looking at beandoc - it can help show where you have misconfigured beans etc.

            Comment

            Working...
            X