Results 1 to 2 of 2

Thread: Define enum as Spring Bean and dependency inject it into another Spring Bean

  1. #1

    Default Define enum as Spring Bean and dependency inject it into another Spring Bean

    I am getting exception when I define an enum class as a Spring bean.

    Code:
    package org.poc;
    
    public enum MyEnum {
    	VAL1,
    	VAL2;
    }
    My XML snippet of code:
    Code:
    <bean id="myEnum" class="org.poc.MyEnum" >
    </bean>
    myEnum bean is not found.

    What am I missing?

  2. #2
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    1. You missed the forum - the question is not related to AOP at all;
    2. Your config declares a new instance of class 'org.poc.MyEnum' that should be instantiated using no-args constructor. It's perfectly expected that such a config fails;


    Regarding solution - is it really necessary for you to have that 'Class' object defined as a separate bean? Isn't it better to directly define it as a target bean property?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •