0

I'm trying to create a webapp with spring remoted services.

The remoting itself is working correclty, however if I want to autowire a bean into the remoted service, the field will remain null, no matter what.

The bean I want to wire into the other is also remoted, and it works fine (it's just a helloworld, so no CDI there).

my 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"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/context https://www.springframework.org/context/spring-context.xsd
                        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<context:annotation-config />
<context:component-scan base-package="hu.bme.sch.qpa" annotation-config="true"/>

<bean id="sessionFactory"
      class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="dataSource"
              ref="dataSource"/>
    <property name="packagesToScan"
              value="hu.bme.sch.qpa.global.entities"/>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.hbm2ddl.auto">
                update
            </prop>
            <prop key="hibernate.dialect">
                org.hibernate.dialect.PostgreSQL95Dialect
            </prop>
        </props>
    </property>
</bean>

<bean id="dataSource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value="jdbc:postgresql://localhost:5432/test"/>
    <property name="username" value="qpapp_server_user"/>
    <property name="password" value="root"/>
</bean>

<bean id="txManager"
      class="org.springframework.orm.hibernate5.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven/>

<bean id="persistenceExceptionTranslationPostProcessor" class=
        "org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

The bean in question:

package hu.bme.sch.qpa.services;

import hu.bme.sch.qpa.global.entities.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service(Persistence.NAME)

public class PersistenceBean implements Persistence {

@Qualifier(HelloWorld.NAME)
@Autowired
private HelloWorld helloWorld;

@Override
public User getUser() {
    User user = new User();
    user.setEmail(helloWorld.getText());
    return user;
    }
}

So I can reach the getUser function from the client servlet, however the helloWorld field is null and therefore it fails.

László Stahorszki
  • 1,102
  • 7
  • 23
  • Do you have a Helloworld class inside package hu.bme.sch.qpa? Why it is not imported into the class in question? – Steephen May 20 '18 at 23:40
  • If this is a new application, skip all of the legacy bits and use Spring Boot. Additionally, use constructor injection instead of field injection. – chrylis -cautiouslyoptimistic- May 20 '18 at 23:55
  • I didn't include it, because it's a really simple helloworld service, having one function, which returns a very simple string. It is annotated, if that's the question – László Stahorszki May 21 '18 at 01:22
  • Also, this question is not a duplicate of the one linked, because the guy in the other question created an instance of a bean manually, which is not the case here – László Stahorszki May 21 '18 at 01:23

0 Answers0