Reputation: 87
I'm developing a java SE application containing a single main class inside a Maven module. The main class invokes classes contained in another Maven modules.
I would like to have an instance of java bean that is common to any application. This Bean will be initialized in the main class and will be called in some underlying classes (located in different maven modules).
For example I want this:
class Main in Main Module Maven
public class Main {
public MySessionBean sessionBean;
public static void main(String[] args) {
sessionBean = new MySessionBean();
sessionBean.setField1("Field1");
sessionBean.setField2("Field2");
CalledClass called = new CalledClass();
}
}
Main Module Maven
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>Main-Module</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.stackoverflow</groupId>
<artifactId>Called-Module</artifactId>
<version>1.0.0</version>
<type>jar</type>
</dependency>
</dependencies>
I want to call the same instance of sessionBean that I instantiate in a Main class.
My idea is to replicate a Session Bean like a Java EE context. In other words I want to use a bean
@ManagedBean
@SessionScoped
in a Java SE context, but I have no idea how to develop it.
Please, can you help me a find a solution and how develop it? Thanks a lot.
Upvotes: 0
Views: 45