Announcement Announcement Module
Collapse
No announcement yet.
Injecting constants as properties Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Injecting constants as properties

    We have a large set of classes on our projects that currently have a private final static long[] containing a set of constants. These constants are security levels a user needs to access the functionality of the class. For example,

    Code:
    private static final java.security.Permission REQUIRED_PERM = new SystemPermission(new long[] {SystemPermission.MANAGE_SECURITY});
    Is there any way to externalize these values in an application context XML so they can be injected?

    Thanks!

  • #2
    Have you looked at Sec. 3.15 "Setting a bean property or constructor arg from a field value", Spring Reference? I'm not sure it's exactly what you are looking for, but might be a good start point.

    Comment


    • #3
      I second that -- I think the only way you can do this is something like this:

      Code:
      class Foo {
       private static final java.security.Permission REQUIRED_PERM;
       public Foo() {
        REQUIRED_PERM= new SystemPermission(new long[] {SystemPermission.MANAGE_SECURITY});
       } 
       public Foo(long[] systemPermissions) {
         REQUIRED_PERM= new SystemPermission(systemPermissions);
       }
      }
      I'm supposing that you can set longs in an applicationContext xml file by seperating them with commas. I'm not sure if you can use the String "SystemPermission.MANAGE_SECURITY" for your <value/> though as Spring might not know how to convert that to a long.

      Comment


      • #4
        BTW, there is a typo in that section of the reference, the first word is 'FileRetrievingFactoryBean'. It should be 'FieldRetrievingFactoryBean'

        "FieldRetrievingFactoryBean is a FactoryBean ..."

        Comment

        Working...
        X