Maven dependency provided on submodule ear throws ClassNotFoundException - maven

Environment:
Java 11
JBoss 7.2
Maven 3.5
I am getting this ERROR java.lang.ClassNotFoundException: net.sf.jasperreports.engine.JRException when I try to execute a method from a class in app-commons module. Jasper dependency in app-commons is compiled and app-commons dependency in app-back is provided.
How could I solve this?
Error
09:29:24,013 SEVERE [org.primefaces.application.exceptionhandler.PrimeExceptionHandler] (default task-1) net/sf/jasperreports/engine/JRException: java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/JRException
...
Caused by: java.lang.ClassNotFoundException: net.sf.jasperreports.engine.JRException from [Module "deployment.accfor2.ear" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:255)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
... 78 more
Modules:
app (pom)
app-ear
app-back
app-commons (provided)
app-front
app-commons (provided)
app-commons
jasperreports (compiled)
...
pom.xml (app-commons)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.name.app</groupId>
<artifactId>app</artifactId>
<version>8.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>app-commons</artifactId>
<packaging>jar</packaging>
<name>app-commons</name>
...
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.15.0</version>
</dependency>
</dependencies>
...
ReportManager.java (app-commons)
public class ReportManager {
...
public static void addParam(Map<String, Object> params, String nom, byte[] compiledReport) throws ReportException {
try {
params.put(nom, SerializationUtils.deserialize(compiledReport));
} catch (Exception e) {
throw new ReportException("Error deserialize compiledReport.");
}
}
...
pom.xml (app-back)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.name.app</groupId>
<artifactId>app</artifactId>
<version>8.0.0</version>
</parent>
<artifactId>app-back</artifactId>
<packaging>war</packaging>
<name>app-back</name>
<description>Módul back (intranet)</description>
<dependencies>
...
<dependency>
<groupId>com.name.app</groupId>
<artifactId>app-commons</artifactId>
<scope>provided</scope>
</dependency>
...
ExecuteReportBean.java (app-back)
public class ExecuteReportBean.java
...
public void compileReport(Informe informe, Map<String, Object> parametresSend) {
ReportManager.compilaReport(parametre.getJasperReport());//ERROR java.lang.ClassNotFoundException: net.sf.jasperreports.engine.JRException
...

If you declare the dependency as provided, it will not be packaged into the WAR.
Either change the scope to compile or let the application server provide it (by e.g. putting it into a JBoss module).

Because of transitive dependencies are not included when dependency is provided, so I had to restructure the modules this way.
Modules:
app (pom)
app-ear
jasperreports (compiled) MOVED FROM APP-COMMONS
app-back
app-commons (provided)
app-front
app-commons (provided)
app-commons
...
I was not able to change app-commons dependency to compiled because it is dependent of app-front and app-back. In app-commons as compiled I have an #ApplicationScope class that it would produce ambiguous Beans pointing to the class in app-commons because of jakartaee context management.

Related

Dependency management in gradle with mavenBom

I have a java library that is imported in gradle like this
sourceControl {
gitRepository("git#github.com/mytest/commonslib.git") {
producesModule("com.lib:commonslib")
}
}
the lib contains a pom.xml with all dependencies.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.lib</groupId>
<artifactId>commonslib</artifactId>
<version>0.1.10</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.7.5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
...
now i would like to import this pom to handle the dependend libraries.
But it does not work when i used it like this.
dependencyManagement {
imports {
mavenBom 'com.lib:commonslib:0.1.10'
}
}
I got the error: Could not resolve commonslib.pom (project :commonslib). Any hint whats wrong? Is it even possible to use producesModule and mavenBom in compbination?

Using #ControllerAdvice as a dependency for another project

I make a common project for listening Exceptions and use #ControllerAdvice with #ExceptionHandler
#ControllerAdvice(annotations = RestController.class)
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
#ExceptionHandler({Exception.class})
#ResponseStatus(value = HttpStatus.NOT_FOUND)
#ResponseBody
public ResponseEntity<ErrorResponse> notFound(Exception ex) {
return new ResponseEntity<>(
new ErrorResponse(ex.getMessage(), 404, "My Custom Message"), HttpStatus.NOT_FOUND);
}
}
without any #SpringBootApplication and main method to adding as dependency to my another project. my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>spring-commons-rest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-commons-rest</name>
<description>for Listening Exceptions</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
after adding its dependency and #ComponentScan to another project, but its not working as Exception handling for response custom Error. I appreciated any help.
I found that was not about using #ComponentScan and with using #Import it will work so fine. but if anyone has any better solution or some guiding line I will appreciate that.
I've solved it by adding
#Order(Ordered.HIGHEST_PRECEDENCE)
to the ControllerAdvice class that you are importing.
In my case, there was another ControllerAdvice class in the downstream project that was taking priority over the one I was importing.

#WicketHomePage not found

Blockquote
J have a Eclipse workspace with a maven parent project (parent) and child > >projects (Domain,Web,Win)
The parent pom contains the wicket-spring-boot-starter-parent
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.SteinKo.ATM</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>Parent</name>
<url>http://maven.apache.org</url>
<modules>
<module>Domain</module>
<module>Web</module>
<module>Win</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<scm>
<connection>scm:git#github.com:steinKo/ATM.git</connection>
<url>https://github.com/steinKo/ATM.git</url>
</scm>
<parent>
<!-- https://mvnrepository.com/artifact/com.giffing.wicket.spring.boot.starter/wicket-spring-boot-starter-parent -->
<groupId>com.giffing.wicket.spring.boot.starter</groupId>
<artifactId></artifactId>
<version>2.0.3</version>
</parent>
The web projects contains a Wicket pages
package steinKo.ATM;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import steinKo.ATM.presentaion.web.HomePage;
#SpringBootApplication
public class Web {
public static void main(String[] args) throws Exception {
new SpringApplicationBuilder().sources(Web.class).run(args);
}
public Class<HomePage> getHomePage() {
return HomePage.class;
}
}
package steinKo.ATM.presentaion.web;
import com.giffing.wicket.spring.boot.context.scan.WicketHomePage;
import org.apache.wicket.markup.html.WebPage;
import steinKo.ATM.domain.ATM;
import steinKo.ATM.domain.Bank;
#WicketHomePage
public class HomePage extends WebPage {
/**
*
*/
private static final long serialVersionUID = 1L;
private ATM atm;
private Bank bank;
public HomePage() {
bank = new Bank();
atm = new ATM(bank);
add(new MenuPanel("menuPanel"));
add(new ContentPanel("contentPanel", atm));
}
}
The pom.xml for the web contain dependency to wicket-spring-boot-starter
http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
<artifactId>Web</artifactId>
<parent>
<groupId>org.SteinKo.ATM</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1</version>
<relativePath />
</parent>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.wicket/wicket-core -->
<dependency>
<groupId>com.giffing.wicket.spring.boot.starter</groupId>
<artifactId>wicket-spring-boot-starter</artifactId>
</dependency>
When I execute maven test on parent project I get the message
[INFO] Scanning for projects...
[ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for com.giffing.wicket.spring.boot.starter:wicket-spring-boot-starter:jar is missing. # org.SteinKo.ATM:Web:[unknown-version], /Users/stein/Development/ATM/Parent/Web/pom.xml, line 20, column 16
[ERROR] 'dependencies.dependency.version' for org.seleniumhq.selenium:selenium-java:jar is missing. # org.SteinKo.ATM:Web:[unknown-version], /Users/stein/Development/ATM/Parent/Web/pom.xml, line 28, column 13 #
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR] The project org.SteinKo.ATM:Web:0.0.1 (/Users/stein/Development/ATM/Parent/Web/pom.xml) has 2 errors
[ERROR] 'dependencies.dependency.version' for com.giffing.wicket.spring.boot.starter:wicket-spring-boot-starter:jar is missing. # org.SteinKo.ATM:Web:[unknown-version], /Users/stein/Development/ATM/Parent/Web/pom.xml, line 20, column 16
[ERROR] 'dependencies.dependency.version' for org.seleniumhq.selenium:selenium-java:jar is missing. # org.SteinKo.ATM:Web:[unknown-version], /Users/stein/Development/ATM/Parent/Web/pom.xml, line 28, column 13
[ERROR]
and
the
import com.giffing.wicket.spring.boot.context.scan.WicketHomePage; and
#WicketHomePage is marked red in the has a message "Can not be resolved"
Why?
It look like maven build issue for me dependencies.dependency.version not properly loading the dependency of com.giffing.wicket.spring.boot.starter from parent . Please build using mvn clean install from parent to all the project and fix . Its nothing to do with code .
And more over i'm not sure whether you shared your full pom add this Your pom not correct change this
<groupId>com.giffing.wicket.spring.boot.starter</groupId>
<artifactId></artifactId>
<version>2.0.3</version>
to
<dependency>
<groupId>com.giffing.wicket.spring.boot.starter</groupId>
<artifactId>wicket-spring-boot-starter</artifactId>
<version>2.0.3</version>
</dependency>

Integrate Spring Boot in an EAR project

I have an existing war project created using spring boot. How to package it within an EAR which has an EJB module?
Is there any way to move the model and dao packages to EJB module and injecting it with WAR module?
You need a parent project that includes a war project, which will be your spring boot project, and an ear project just for making your ear.
Parent will need to have the spring boot as its parent :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
<groupId>com.greg</groupId>
<artifactId>ear-example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<myproject.version>1.0-SNAPSHOT</myproject.version>
</properties>
<name>ear-example</name>
<modules>
<module>example-ear</module>
<module>example-war</module>
</modules>
</project>
Your ear project is:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.greg</groupId>
<artifactId>ear-example</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>example-ear</artifactId>
<packaging>ear</packaging>
<dependencies>
<dependency>
<groupId>com.greg</groupId>
<artifactId>example-war</artifactId>
<version>${project.version}</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<modules>
<webModule>
<groupId>com.greg</groupId>
<artifactId>example-war</artifactId>
<contextRoot>/appname</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
</project>
You have to use the dependency management system.
It allows you to set the parent of a Spring Boot WAR module project that is different from spring-boot-starter-parent. It would make it possible to include the WAR project into EAR in the same way just like any other.
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
... then you would use starter dependencies in the usual way:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
Shared dependencies may be specified by the root level pom while the individual ones might be a module bounded.
Using Spring Boot without the parent POM
I have created a multi module gradle project including a spring RESTFul web services -
EAR application name is - bluestone
bluestone/settings.gradle -
rootProject.name = 'bluestone'
include ':bluestone-web'
include ':bluestone-core'
include ':bluestone-rest'
project (':bluestone-web').projectDir = new File('bluestone-web')
project (':bluestone-core').projectDir = new File('bluestone-core')
project (':bluestone-rest').projectDir = new File('bluestone-rest')
bluestone-rest project structure is -
bluestone-rest/build.gradle
plugins {
id 'war'
}
group 'com.bluestone.smart.rest'
version '1.0-SNAPSHOT'
dependencies {
compile library.spring_context
compile library.spring_web
compile library.spring_beans
compile library.spring_mvc
providedCompile library.servlet_api
testCompile library.junit
}
all the dependencies are imported from common libraries.gradle. common libraries.gradle is user ear bluestone/libraries.gradle
/* ============================================================================
Library definitions for project 'Bluestone'
============================================================================
Define here library dependencies and use them inside sub-modules build.gradle.
Included from: "${rootProject.projectDir}/build.gradle"
============================================================================
*/
ext {
library = [
/* testing */
junit: "junit:junit:4.12",
log4j: "log4j:log4j:1.2.17",
/* Spring libraries*/
spring_context: "org.springframework:spring-context:${spring_lib_version}",
spring_aop: "org.springframework:spring-aop:${spring_lib_version}",
spring_beans: "org.springframework:spring-beans:${spring_lib_version}",
spring_orm: "org.springframework:spring-orm:${spring_lib_version}",
spring_web: "org.springframework:spring-web:${spring_lib_version}",
spring_mvc: "org.springframework:spring-webmvc:${spring_lib_version}",
servlet_api: "javax.servlet:javax.servlet-api:4.0.1"
]
}
Within bluestone-rest, i have created three basic file to test a sample rest message -
spring Configuration named - BlueRestConfiguration.java
package com.bluestone.smart.rest.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
#Configuration
#EnableWebMvc
#ComponentScan(basePackages = {"com.bluestone.smart.rest.resources", "com.bluestone.smart.rest.controller"})
public class BlueRestConfiguration {
}
Initialization file - named is - RestInit.java
package com.bluestone.smart.rest.config;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import javax.servlet.ServletContext;
public class RestInit extends AbstractAnnotationConfigDispatcherServletInitializer {
/**
* Specify {#code #Configuration} and/or {#code #Component} classes for the
* {#linkplain #createRootApplicationContext() root application context}.
*
* #return the configuration for the root application context, or {#code null}
* if creation and registration of a root context is not desired
*/
#Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] {BlueRestConfiguration.class};
}
/**
* Specify {#code #Configuration} and/or {#code #Component} classes for the
* {#linkplain #createServletApplicationContext() Servlet application context}.
*
* #return the configuration for the Servlet application context, or
* {#code null} if all configuration is specified through root config classes.
*/
#Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
/**
* Specify the servlet mapping(s) for the {#code DispatcherServlet} —
* for example {#code "/"}, {#code "/app"}, etc.
*
* #see #registerDispatcherServlet(ServletContext)
*/
#Override
protected String[] getServletMappings() {
return new String[] {"/"};
}
}
A rest service API - named - GreetingsController.java
package com.bluestone.smart.rest.resources;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class GreetingsController {
#RequestMapping(path = "/greeting", method = RequestMethod.GET)
public String greetings(){
return "Welcome Spring Rest!";
}
}
finally build this EAR application using -
gradlew clean build
and deploy on WildFly application and then calling this service using postman -
Please let me know if any more details required. I shall push this code on git and will share the git link here.

Can find imported Spring beans from JAR, but not from WAR

My application consists of three Maven projects (I am omitting other modules)): FrameworkBase (JAR), FrameworkBaseImpl (JAR), FrameworkRestService (WAR).
FrameworkRestService is a plugin to FrameworkBaseImpl, drawing its class/interface definitions
from FrameworkBase, which FrameworkBaseImpl implements/extends. (I had to split FrameworkBase to avoid Maven curcular dependencies).
FrameworkBaseImpl has a main, which invokes Jetty, passing the FrameworkRestService war.
I am trying to have Spring inject a RestService instance as a field member in the (sole) instance of FrameworkMain class of FrameworkBaseImpl. My Spring points to FrameworkRestService class inside FrameworkRestService project as implementing the restService bean.
And here is the problem: Although Spring seems to find the imported framework_rest_service.context file in the WAR that contains the bean it fails injecting it (no bean named restService is found). But if I convert FrameworkRestService into a JAR - it magically succeeds! I am stuck for 2 days on it! Please help!
FrameworkBase pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>framework.base</artifactId>
<packaging>jar</packaging>
<name>framework.base</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>controlapps</groupId>
<artifactId>controlapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../controlapp/pom.xml</relativePath>
</parent>
</project>
FrameworkBase RestService:
package com.company.controlapps.framework.base;
public class RestService {
public FrameworkMain frameworkMain;
/* Setters for Spring */
public void setFrameworkMain(FrameworkMain frameworkMain)
{this.frameworkMain = frameworkMain;}
}
FrameworkBase FrameworkMain:
package com.company.controlapps.framework.base;
public interface FrameworkMain {
...
}
FrameworkBaseImpl pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>framework.base.impl</artifactId>
<packaging>jar</packaging>
<name>framework.base.impl</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>controlapps</groupId>
<artifactId>controlapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../controlapp/pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>controlapps</groupId>
<artifactId>framework.base</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>controlapps</groupId>
<artifactId>framework.restservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>runtime</scope>
<type>war</type>
</dependency>
</dependencies>
</project>
FrameworkBaseImpl FrameworkMainImpl:
package com.company.controlapps.framework.base.impl;
public class FrameworkMainImpl implements FrameworkMain {
....
protected RestService restService;
public void setRestService(RestService restService)
{this.restService = restService;}
}
public static void main(String[] args) {
context = new ClassPathXmlApplicationContext(SPRING_CONTEXT_FILENAME);
FrameworkMainImpl frameworkMain = (FrameworkMainImpl) context.getBean("frameworkMain");
...
}
FrameworkBaseImpl spring context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<import resource="classpath*:framework_restservice_context.xml"/>
<bean id="frameworkMain" class="com.company.controlapps.framework.base.impl.FrameworkMainImpl" >
<property name="restService" ref="restService" />
</bean>
</beans>
FrameworkRestService FrameworkRestService pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>framework.restservice</artifactId>
<packaging>war</packaging>
<name>framework.restservice</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jersey.version>1.12</jersey.version>
</properties>
<parent>
<groupId>controlapps</groupId>
<artifactId>controlapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../controlapp/pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>controlapps</groupId>
<artifactId>framework.base</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server-linking</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.5.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
</project>
FrameworkRestService spring framework_restservice_context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="restService" class="com.radware.controlapps.framework.restservice.FrameworkRestService">
<property name="frameworkMain" ref="frameworkMain" />
</bean>
</beans>
FrameworkRestService FrameworkRestService.java snippet:
package com.company.controlapps.framework.restservice;
#Path("myresource")
public class FrameworkRestService extends RestService {
...
#Context
UriInfo uriInfo;
#Context
Request request;
#GET
#Produces(MediaType.APPLICATION_JSON)
public MyResource getMyResource() {
...
frameworkMain.doSomething();
....
}
Sorry for the long question. :-)
It wasn't a class loader issue. I had the WAR and the JAR use the same class loader (of the JAR). Somebody commented that I shouldn't have tried to link a WAR and look for beans in there.
So instead of trying to solve the problem I simply bypassed it by canceling Spring dependencies between the JAR and the WAR. In the WAR I still needed a reference to the FrameworkMain singleton instantiated in the JAR.
I "hacked" this as follows: I added a class named Holder with public static methods get and set the FrameworkMain instance singleton. I call get from the WAR, and set from the jar. I could not add this to FrameworkMain, which is actually an interface in FrameworkBase jar (implemented by FrameworkMainImpl in the FrameworkBaseImpl jar).
Thanks.

Resources