Results 1 to 3 of 3

Thread: Inject of Bean with Custom Annotation

  1. #1

    Default Inject of Bean with Custom Annotation

    Hi everybody,
    we decide to use a custom set of configuration mapped on db with a custom structure.

    So I decide to use a custom annotation like this:
    Code:
    @Service
    @Retention(RetentionPolicy.RUNTIME)
    public @interface ConfigurationNode {
    	String path();
    
    	String key();
    }
    and another annotation

    Code:
    @Service
    @Retention(RetentionPolicy.RUNTIME)
    public @interface DbConfig {
    
    }
    I annotated a field on my bean:

    Code:
    @DbConfig
    @Transactional
    public class TestDao {
    
    	Logger logger = LoggerFactory.getLogger(TestDao.class);
    
    	@Autowired
    	FolderDao folderDao;
    
    	@Autowired
    	NodeDao nodeDao;
    
    	@ConfigurationNode(path = "CBOX/WEBAPP/WEBAPP/WEBAPP", key = "size")
    	Node test;
    All i want to do is intercept my annotation and putting the correct value during bean injection.


    So i think to build a factory.
    Code:
    @Configuration
    public class DBConfigurationScanContext {
    
    @Bean
    Object getObject(String path, String key){
    return new Object();
    }
    
    }
    There is a way to pass to my @Bean annotation the parameter of my custom annotation?

    Or there is a more efficent way to build a custom bean?

  2. #2
    Join Date
    Jun 2012
    Location
    New York
    Posts
    1

    Default

    I think It is true. Thanks for sheering this information.
    hcg diet
    Last edited by JesseMHunter; Jun 7th, 2012 at 03:20 AM. Reason: some mistake

  3. #3

    Default

    Unuseful comment
    Last edited by luca.preziati; Jun 8th, 2012 at 03:00 AM.

Posting Permissions

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