0

Noobish question here, but I'm struggling to make this work.

I've an old project with submodules which does not use Spring or anything, just final class and static Instance.

--- Main

------ Server

------ Business

------ Webservices


Server has a dependency with Business and Webservices.

Webservices has a dependency with Business

Server is the sub-module with the web.xml file.


I have to add a new service in Business sub-module and I want to start using Spring and dependency injection to do so, in order to start migrating the project to Spring. (I'm not talking SpringBoot, just regular Spring).


In Business sub-module, I did:

  • add spring-core, spring-beans, spring-contet dependencies as well as javax.inject . Using spring version 4.3.2
  • create an interface IMyService and its implementation MyServiceImpl and added the @Service annotation on the impl.
  • add a spring-context.xml file in src/main/resources declaring context:annotation-config and context:component-scan base-package

Then I created, in my submodule a "bridge" to try and use the Spring bean from my submodule in a non spring bean of another submodule, like described here : https://blog.jdriven.com/2015/03/using-spring-managed-bean-in-non-managed-object/

However the context never get injected.

I've tried adding in the web.xml of Server the contextConfigLocation but no dice either.

What Am I missing so that my Spring context get initialized in the Business module ?

TheBakker
  • 2,852
  • 2
  • 28
  • 49
  • 1
    Have you implemented a https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/context/ContextLoaderListener.html to load the context? https://stackoverflow.com/questions/11815339/role-purpose-of-contextloaderlistener-in-spring has information on its purpose. – Darren Forsythe Sep 25 '17 at 21:29
  • Thanks bit confused as to how to declae the ContextListener as I do not want to use Spring for the View, just for business services. Do I still need to declare it on servlet level ? – TheBakker Sep 25 '17 at 21:36
  • The ContextListener isn't for the `view` it's for creating the ApplicationContext and tieing it to the life of the servlet. – Darren Forsythe Sep 25 '17 at 21:41
  • I have the following in my web.xml in JBOSS contextConfigLocation classpath:context.xml org.jboss.resteasy.plugins.spring.SpringContextLoaderListener – maximus Sep 25 '17 at 21:42
  • @DarrenForsythe so I'm to add spring-web dependency to be able to declare the `ContextLoaderListener`. Ok thought I could do without that. – TheBakker Sep 25 '17 at 21:55

0 Answers0