Java WAR - Load Spring beans from an external JAR

前端 未结 1 1527
遇见更好的自我
遇见更好的自我 2021-01-13 14:53

I would like to load inside my Spring MVC Web Application (packaged as WAR) some Spring framework beans annotated with @Service from an externa

相关标签:
1条回答
  • 2021-01-13 15:30

    WAR´s appContext.xml and WAR´s web xml are both feasible. If you need to run integration tests based on both localSpringContext.xml and external jar's applicationContext.xml frequently, I recommend the WAR´s appContext.xml approach.

    Updated1:

    WAR´s appContext.xml:

    <import resource="classpath:{classpath}/applicationContext.xml"/>
    

    WAR´s web xml:

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:localSpringContext.xml
            classpath:{classpath}/applicationContext.xml
    </param-value>
    </context-param>
    

    For example, if your applicationContext.xml is under package :com/gmail/hippoom

    you can get it by classpath:com/gmail/hippoom/applicationContext.xml or classpath*:applicationContext.xml with wildcard.

    0 讨论(0)
提交回复
热议问题