I have a ID Generator application which will be packaged as a Jar, I have some beans created which needs to be used in my Main application. I am not able to inject the beans from my Jar into my main application. Can anyone please point me in the right direction on how to achieve this?
Asked
Active
Viewed 31 times
1 Answers
0
The easiest way would be to declare the bean in your Main application in a configuration class.
@Configuration
public class MyConfig {
@Bean
public MyBean myBean {
return new MyBean();
}
}
or
@SpringBootApplication
public class MyApplication {
@Bean
public MyBean myBean {
return new MyBean();
}
public static void main( String[] args ) {
SpringApplication.run( MyApplication.class, args );
}
}
Now MyBean can be autowired in as a dependency.
@Service
public class MyService {
@Autowired
MyBean myBean;
}

Chris Savory
- 2,597
- 1
- 17
- 27