0

I have a project with XML based spring configuration and want to define some new beans but in java class based configuration.

How to implement this so that i can also refer beans of java configuration in my XML config file.

1 Answer 1

2

You can import your xml config into java configuration, like so:

@Configuration
@ImportResource("classpath:pl/rav/springtest/resources/app.xml")
public class AppConfig {
    @Bean(name="myMessageService")
    MessageService mockMessageService() {
        return new MessageServiceImpl();
    }
}

When you want to refer from xml to the bean you just point to its name:

<property name="msgSrv">
    <ref bean="myMessageService"/>
</property>

Then use ApplicationContext based on your java configuration.

    ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

As you started with xml config, you may be interested in other way around (importing java config into xml config) which I think was explained here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.