0

Is there any way I can 2 sources in SpringApplication.run()? Here is my main class. You can clearly understand what I've tried so far.

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {

    /*
     * SPRING BOOTSTRAP MAIN
     */
    public static void main(String[] args) {
//        SpringApplication.run(com.twitter.Application.class, args);
//        SpringApplication.run(com.linkedin.Application.class, args);
        Object[] sources = new Object[2];
        sources[0] = com.twitter.Application.class;
        sources[1] = com.linkedin.Application.class;
        SpringApplication.run(sources, args);
    }

}

If I run..

SpringApplication.run(com.twitter.Application.class, args);
SpringApplication.run(com.linkedin.Application.class, args);

com.linkedin.Application.class gives an error because address is already in use.

If i run..

sources[0] = com.twitter.Application.class;
sources[1] = com.linkedin.Application.class;
SpringApplication.run(sources, args);

Linkedin works fine, twitter is not. '/twitter' mapping (which I've given for TwitterController) gives an white label.

Krishnalal P
  • 487
  • 4
  • 20
  • The sources are nothing more then `@Configuration` classes. Why would you need to entry points (i..e main methods) for your application. Just configure twitter and Facebook in a single application. – M. Deinum Oct 16 '14 at 06:36
  • That is a strange behavior, your second approach appears perfectly fine. Just to be sure if you have your twitter related source alone, the `/twitter` mapping works cleanly then? – Biju Kunjummen Oct 16 '14 at 09:28

1 Answers1

0

On the surface, this looks like a Spring Boot-specific question (which it really is), but what it looks like to me is that you want your application to support both Twitter and LinkedIn. Right?

All you're passing into SpringApplication.run() is a set of configuration classes. Typically, you'd only pass in one configuration and let component-scanning find other @Configuration classes automatically. And, although it's not required, you'd typically pass in a configuration class that also has the main() method that kicks it off.

So why do you have an Application class with a main method and then two more Application classes (which you haven't shared source for, but I'm guessing that they're essentially duplicates of each other with LinkedIn and Twitter being the only differences. If that's the case, what you really want is a configuration class that configures Spring Social, is annotated with @Configuration (which means that component-scanning can pick it up), and can be named anything you want. There's no need to pass it into SpringApplication.run(). Instead, you'll just pass that main Application.class into Spring Application.run().

Take a look at https://github.com/spring-projects/spring-social-samples/blob/master/spring-social-showcase-boot/src/main/java/org/springframework/social/showcase/config/Application.java for an example of how I do it in the Boot-enabled Spring Social Showcase. There, Application.java passes itself into SpringApplication.run(). And since it enables component-scanning, the other configuration classes will be discovered and used, too.

Of course, maybe I misunderstood what you're trying to do. If so, then please restate what you're trying to accomplish and I'll try to help.

Craig Walls
  • 2,080
  • 1
  • 12
  • 13