Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5928789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:20:02+00:00 2026-05-22T14:20:02+00:00

I am writing Apache CXF web services and use Spring for loading my beans.

  • 0

I am writing Apache CXF web services and use Spring for loading my beans. My only bean is calling external process (MATLAB) from Java. My beans definition looks as below:

<bean id="matlabEngine" class="org.burch.pca.matlab.MatlabEngine"
    init-method="start" scope="singleton">
    <constructor-arg value="${matlab.engine.path}"></constructor-arg>
</bean>

<bean
    class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    <property name="searchContextAttributes" value="true" />
    <property name="contextOverride" value="true" />
    <property name="ignoreResourceNotFound" value="true" />
    <property name="locations">
        <list>
            <value>classpath:/pca-engine.properties</value>
        </list>
    </property>
</bean>

Piece of my MatlabEngine bean is as below:

/**
 * Path to MATLAB engine.
 */
private String pathToEngine;

public MatlabEngine(String pathToEngine) throws MatlabConnectionException, MatlabInvocationException{
    super();
    setPathToEngine(pathToEngine);
}

/**
 * Starts engine and goes to path defined by argument
 * @param pathToEngine
 * @throws MatlabConnectionException
 * @throws MatlabInvocationException
 */
public void start() throws MatlabConnectionException, MatlabInvocationException{
  //Create a factory
  RemoteMatlabProxyFactory factory = new RemoteMatlabProxyFactory();

  //Get a proxy, launching MATLAB in the process
  proxy = factory.getProxy();

  //Display welcoming messages in MATLAB Command Window
  proxy.eval(MatlabCommandsRegistry.disp(MATLAB_ENGINE_WELCOME_1));
  proxy.eval(MatlabCommandsRegistry.disp(MATLAB_ENGINE_WELCOME_2));

  if(pathToEngine!= null && !"".equals(pathToEngine)){
      logM("Switching to engine directory...");
      String goToEngineRootDir = MatlabCommandsRegistry.cd(pathToEngine);
      proxy.eval(goToEngineRootDir);
      logM("Sucessfully changed engine dir to "+pathToEngine);
  }
}

When I deploy web services in Tomcat, it brings up MATLAB process nicely (bean gets loaded).

However, when I create client request to web service endpoint with this code:

public static void main(String args[]) throws Exception {

    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

    factory.getInInterceptors().add(new LoggingInInterceptor());
    factory.getOutInterceptors().add(new LoggingOutInterceptor());
    factory.setServiceClass(UploadService.class);
    factory.setAddress("http://localhost:8080/auth-ws-1.0.0/services/upload");
    UploadService client = (UploadService) factory.create();

    UploadEntity resume=new UploadEntity();
    resume.setFileName("Image490");
    resume.setFileType("jpg");

    //Work arround data handler....
    DataSource source = new FileDataSource(new File("C:\\Users\\Pictures\\thumb.png"));
    DataHandler dataHandle = new DataHandler(source);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    dataHandle.writeTo(stream);
    resume.setPayload(stream.toByteArray());
    client.uploadFile(resume);
    System.exit(0);

}

my server brings out new instance of MATLAB process (bean gets loaded again – very heavy and undesirable). What could I do to have only one bean which will be used to serve all processing and all requests? I am new to Spring, and I am thinking that my problem is that I am dealing with multiple contexts here. I want them to share a single instance of a singleton bean but don’t know how to manage this.

Thank you for your time!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:20:03+00:00Added an answer on May 22, 2026 at 2:20 pm

    You should enable singleton mode for you bean.

    Look at this: http://static.springsource.org/spring/docs/1.2.x/reference/beans.html#beans-factory-modes

    Bean defenition may looks like this:

    <!-- Spring property loading bean -->
    <bean
        class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer" singleton="true">
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        <property name="searchContextAttributes" value="true" />
        <property name="contextOverride" value="true" />
        <property name="ignoreResourceNotFound" value="true" />
        <property name="locations">
            <list>
                <value>classpath:/pca-engine.properties</value>
            </list>
        </property>
    </bean>
    

    I think you should manage MATLAB process lifecircle wisely to decrease resource loading.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a small web application using Perl, HTML::Mason and Apache. I've been using
I am writing an Android project that needs to use the Apache HttpClient from
I am writing a web application that uses Apache Commons config to read/write a
I'm writing an Apache module and want to get a string with the Apache
I am writing an Apache module in C++. I need to store the common
I'm starting a project that involves writing mailets for Apache James . As far
I am writing xmlrpc codes to communicate between Apache XML-RPC client and a Python
I am writing some XML -> PDF generating templates in Apache FOP for an
I'm using dlopen() in an Apache module that I am writing so that I
I'm writing a python script to extract data out of our 2GB Apache access

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.