Unable to import spring configuration class from project A into project B









up vote
0
down vote

favorite












I have below classes in project A which is a spring project



@Configuration
class MyConfig
@Bean
JmsTemplate jmsTemplate()
return new JmsTemplate();


@Bean
Test test()
return new Test();



class Test
@Autowired
JmsTemplate jmsTemplate;

@PostConstuct
public void init()
System.out.println("Test Constructed")


public void sendOrder()
System.out.println("Sending Order");




And I have below in Project B



@SpringBootApplication
class MySpringBootApp

public static void main(String args)
final SpringApplication app = new SpringApplication(MainConfig.class);
app.run(args);



@Configuration
@Import(MyConfig.class)
class MainConfig implements CommandLineRunner

@Autowired
Test test;

@Override
public void run(String... strings) throws Exception
System.out.println("Placing order");
test.sendOrder()




I have included project A in the pom of project B as dependency



Neither SYS OUT from post construct or sendOrder from Test class is printed. SYS OUT in run method from MainConfig is printed .. I am not sure if MyConfig class from project A is included in project B, There are no compilation nor run-time errors. Any leads appreciated










share|improve this question























  • try annotating MyConfig class with @Configuration
    – sarath kumar
    Nov 11 at 3:57










  • In your main class why you have mentioned MainConfig.class. I think it should be Myspringbootapp.class which is your mainboot class. Also check your class Test of package A, cant see it’s component class or what?
    – GauravRai1512
    Nov 11 at 3:58











  • Added @Configuration to MyConfig, but didnt work.
    – coder
    Nov 11 at 4:19










  • @coder i have given my comment can you please implement and test it again.
    – GauravRai1512
    Nov 11 at 13:15










  • Hi Gaurav, i added MySpingBootApp but still no luck
    – coder
    Nov 11 at 15:27














up vote
0
down vote

favorite












I have below classes in project A which is a spring project



@Configuration
class MyConfig
@Bean
JmsTemplate jmsTemplate()
return new JmsTemplate();


@Bean
Test test()
return new Test();



class Test
@Autowired
JmsTemplate jmsTemplate;

@PostConstuct
public void init()
System.out.println("Test Constructed")


public void sendOrder()
System.out.println("Sending Order");




And I have below in Project B



@SpringBootApplication
class MySpringBootApp

public static void main(String args)
final SpringApplication app = new SpringApplication(MainConfig.class);
app.run(args);



@Configuration
@Import(MyConfig.class)
class MainConfig implements CommandLineRunner

@Autowired
Test test;

@Override
public void run(String... strings) throws Exception
System.out.println("Placing order");
test.sendOrder()




I have included project A in the pom of project B as dependency



Neither SYS OUT from post construct or sendOrder from Test class is printed. SYS OUT in run method from MainConfig is printed .. I am not sure if MyConfig class from project A is included in project B, There are no compilation nor run-time errors. Any leads appreciated










share|improve this question























  • try annotating MyConfig class with @Configuration
    – sarath kumar
    Nov 11 at 3:57










  • In your main class why you have mentioned MainConfig.class. I think it should be Myspringbootapp.class which is your mainboot class. Also check your class Test of package A, cant see it’s component class or what?
    – GauravRai1512
    Nov 11 at 3:58











  • Added @Configuration to MyConfig, but didnt work.
    – coder
    Nov 11 at 4:19










  • @coder i have given my comment can you please implement and test it again.
    – GauravRai1512
    Nov 11 at 13:15










  • Hi Gaurav, i added MySpingBootApp but still no luck
    – coder
    Nov 11 at 15:27












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have below classes in project A which is a spring project



@Configuration
class MyConfig
@Bean
JmsTemplate jmsTemplate()
return new JmsTemplate();


@Bean
Test test()
return new Test();



class Test
@Autowired
JmsTemplate jmsTemplate;

@PostConstuct
public void init()
System.out.println("Test Constructed")


public void sendOrder()
System.out.println("Sending Order");




And I have below in Project B



@SpringBootApplication
class MySpringBootApp

public static void main(String args)
final SpringApplication app = new SpringApplication(MainConfig.class);
app.run(args);



@Configuration
@Import(MyConfig.class)
class MainConfig implements CommandLineRunner

@Autowired
Test test;

@Override
public void run(String... strings) throws Exception
System.out.println("Placing order");
test.sendOrder()




I have included project A in the pom of project B as dependency



Neither SYS OUT from post construct or sendOrder from Test class is printed. SYS OUT in run method from MainConfig is printed .. I am not sure if MyConfig class from project A is included in project B, There are no compilation nor run-time errors. Any leads appreciated










share|improve this question















I have below classes in project A which is a spring project



@Configuration
class MyConfig
@Bean
JmsTemplate jmsTemplate()
return new JmsTemplate();


@Bean
Test test()
return new Test();



class Test
@Autowired
JmsTemplate jmsTemplate;

@PostConstuct
public void init()
System.out.println("Test Constructed")


public void sendOrder()
System.out.println("Sending Order");




And I have below in Project B



@SpringBootApplication
class MySpringBootApp

public static void main(String args)
final SpringApplication app = new SpringApplication(MainConfig.class);
app.run(args);



@Configuration
@Import(MyConfig.class)
class MainConfig implements CommandLineRunner

@Autowired
Test test;

@Override
public void run(String... strings) throws Exception
System.out.println("Placing order");
test.sendOrder()




I have included project A in the pom of project B as dependency



Neither SYS OUT from post construct or sendOrder from Test class is printed. SYS OUT in run method from MainConfig is printed .. I am not sure if MyConfig class from project A is included in project B, There are no compilation nor run-time errors. Any leads appreciated







java spring-mvc spring-boot junit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 4:16

























asked Nov 11 at 3:49









coder

85




85











  • try annotating MyConfig class with @Configuration
    – sarath kumar
    Nov 11 at 3:57










  • In your main class why you have mentioned MainConfig.class. I think it should be Myspringbootapp.class which is your mainboot class. Also check your class Test of package A, cant see it’s component class or what?
    – GauravRai1512
    Nov 11 at 3:58











  • Added @Configuration to MyConfig, but didnt work.
    – coder
    Nov 11 at 4:19










  • @coder i have given my comment can you please implement and test it again.
    – GauravRai1512
    Nov 11 at 13:15










  • Hi Gaurav, i added MySpingBootApp but still no luck
    – coder
    Nov 11 at 15:27
















  • try annotating MyConfig class with @Configuration
    – sarath kumar
    Nov 11 at 3:57










  • In your main class why you have mentioned MainConfig.class. I think it should be Myspringbootapp.class which is your mainboot class. Also check your class Test of package A, cant see it’s component class or what?
    – GauravRai1512
    Nov 11 at 3:58











  • Added @Configuration to MyConfig, but didnt work.
    – coder
    Nov 11 at 4:19










  • @coder i have given my comment can you please implement and test it again.
    – GauravRai1512
    Nov 11 at 13:15










  • Hi Gaurav, i added MySpingBootApp but still no luck
    – coder
    Nov 11 at 15:27















try annotating MyConfig class with @Configuration
– sarath kumar
Nov 11 at 3:57




try annotating MyConfig class with @Configuration
– sarath kumar
Nov 11 at 3:57












In your main class why you have mentioned MainConfig.class. I think it should be Myspringbootapp.class which is your mainboot class. Also check your class Test of package A, cant see it’s component class or what?
– GauravRai1512
Nov 11 at 3:58





In your main class why you have mentioned MainConfig.class. I think it should be Myspringbootapp.class which is your mainboot class. Also check your class Test of package A, cant see it’s component class or what?
– GauravRai1512
Nov 11 at 3:58













Added @Configuration to MyConfig, but didnt work.
– coder
Nov 11 at 4:19




Added @Configuration to MyConfig, but didnt work.
– coder
Nov 11 at 4:19












@coder i have given my comment can you please implement and test it again.
– GauravRai1512
Nov 11 at 13:15




@coder i have given my comment can you please implement and test it again.
– GauravRai1512
Nov 11 at 13:15












Hi Gaurav, i added MySpingBootApp but still no luck
– coder
Nov 11 at 15:27




Hi Gaurav, i added MySpingBootApp but still no luck
– coder
Nov 11 at 15:27












1 Answer
1






active

oldest

votes

















up vote
0
down vote













I think the issue is in the main class.
You forgot to include the spring boot application itself (MySpringBootApp.class in this case) into the configuration list.



It should be:



@SpringBootApplication
class MySpringBootApp

public static void main(String args)
final SpringApplication app = new
SpringApplication(MySpringBootApp.class,MainConfig.class);
app.run(args);







share|improve this answer




















  • Hi i added MySpringBootApp class into the configuration list, but still no luck. Not sure what is missing?
    – coder
    Nov 11 at 15:27










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245689%2funable-to-import-spring-configuration-class-from-project-a-into-project-b%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













I think the issue is in the main class.
You forgot to include the spring boot application itself (MySpringBootApp.class in this case) into the configuration list.



It should be:



@SpringBootApplication
class MySpringBootApp

public static void main(String args)
final SpringApplication app = new
SpringApplication(MySpringBootApp.class,MainConfig.class);
app.run(args);







share|improve this answer




















  • Hi i added MySpringBootApp class into the configuration list, but still no luck. Not sure what is missing?
    – coder
    Nov 11 at 15:27














up vote
0
down vote













I think the issue is in the main class.
You forgot to include the spring boot application itself (MySpringBootApp.class in this case) into the configuration list.



It should be:



@SpringBootApplication
class MySpringBootApp

public static void main(String args)
final SpringApplication app = new
SpringApplication(MySpringBootApp.class,MainConfig.class);
app.run(args);







share|improve this answer




















  • Hi i added MySpringBootApp class into the configuration list, but still no luck. Not sure what is missing?
    – coder
    Nov 11 at 15:27












up vote
0
down vote










up vote
0
down vote









I think the issue is in the main class.
You forgot to include the spring boot application itself (MySpringBootApp.class in this case) into the configuration list.



It should be:



@SpringBootApplication
class MySpringBootApp

public static void main(String args)
final SpringApplication app = new
SpringApplication(MySpringBootApp.class,MainConfig.class);
app.run(args);







share|improve this answer












I think the issue is in the main class.
You forgot to include the spring boot application itself (MySpringBootApp.class in this case) into the configuration list.



It should be:



@SpringBootApplication
class MySpringBootApp

public static void main(String args)
final SpringApplication app = new
SpringApplication(MySpringBootApp.class,MainConfig.class);
app.run(args);








share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 4:40









Mark Bramnik

11.3k32445




11.3k32445











  • Hi i added MySpringBootApp class into the configuration list, but still no luck. Not sure what is missing?
    – coder
    Nov 11 at 15:27
















  • Hi i added MySpringBootApp class into the configuration list, but still no luck. Not sure what is missing?
    – coder
    Nov 11 at 15:27















Hi i added MySpringBootApp class into the configuration list, but still no luck. Not sure what is missing?
– coder
Nov 11 at 15:27




Hi i added MySpringBootApp class into the configuration list, but still no luck. Not sure what is missing?
– coder
Nov 11 at 15:27

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245689%2funable-to-import-spring-configuration-class-from-project-a-into-project-b%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Darth Vader #20

Ondo