Announcement Announcement Module
Collapse
No announcement yet.
Inject of Bean with Custom Annotation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    I think It is true. Thanks for sheering this information.
    hcg diet
    Last edited by JesseMHunter; Jun 7th, 2012, 04:20 AM. Reason: some mistake

    Comment


    • #3
      Unuseful comment
      Last edited by luca.preziati; Jun 8th, 2012, 04:00 AM.

      Comment

      Working...
      X