Spring RMI

0

Witam
Chciałem stworzyć prostą aplikację składającą sie z klienta oraz serwera wykorzystując do tego technologie wymienione w temacie.
Serwer miał być usługą do której klient będzie wysyłał albo pobierał Stringa wywołując jego metody. Zdefiniowałem interfejs który jest implementowany przez główna klase serwera.

Kod interfejsu oraz implementującej go klasy:

public interface UserService {
    
    public boolean sentTextMessage(String string);
    
    public boolean getTextMessage(int i);
    
}

public class UserServiceImpl implements UserService {

    ArrayList<String> messages = new ArrayList();
    
    @Override
    public boolean sentTextMessage(String string) {
        
        messages.add(string);      
        return false;       
    }

    @Override
    public boolean getTextMessage(int i) {
        
        messages.get(i);
        return false;      
    }

    public ArrayList<String> getMessage() {
        return messages;
    }

    public void setMessage(ArrayList<String> messages) {
        this.messages = messages;
    }
    
    
}

W aplikacji serwerowej zaimplementowałem jako komponent w pliku xml RmiServiceExporter aby udostępnić UserServiceImpl jako usługe.

<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="UserServiceImpl" class="main.chat.springchat.UserServiceImpl" >
    </bean>
 
    <!-- RMI Server Declaration -->
    <bean class="org.springframework.remoting.rmi.RmiServiceExporter">
 
        <!-- serviceName represents RMI Service Name -->
        <property name="serviceName" value="UserServiceImpl"/>
 
        <!-- service represents RMI Object(RMI Service Impl) -->
        <property name="service" ref="UserServiceImpl"/>
 
        <!-- serviceInterface represents RMI Service Interface exposed -->
        <property name="serviceInterface" value="main.chat.springchat.UserService"/>
 
        <!-- defaults to 1099 -->
        <property name="registryPort" value="1099"/>
 
    </bean>
   
</beans>

Jak równiej w części klienckiej zdefiniowałem RmiProxyFactoryBean jako pośrednik.

<?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/spring-context-3.1.xsd"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
    
    <!-- RMI Client Declaration -->
    <bean id="UserServiceImpl" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
 
        <!-- serviceUrl represents RMI Service Url called-->
        <property name="serviceUrl" value="rmi://localhost:1099/UserServiceImpl"/>
 
        <!-- serviceInterface represents RMI Service Interface called -->
        <property name="serviceInterface" value="main.chat.springchat.UserService"/>
 
        <!-- refreshStubOnConnectFailure enforces automatic re-lookup of the stub if a
                            call fails with a connect exception -->
        <property name="refreshStubOnConnectFailure" value="true"/>
 
    </bean>

</beans>

Uruchomiłem część serwerową i dostałem na starcie taki oto wyjątek.

INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@63388a78: defining beans [UserServiceImpl,org.springframework.remoting.rmi.RmiServiceExporter#0]; root of factory hierarchy

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.remoting.rmi.RmiServiceExporter#0' defined in class path resource [spring_server.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice

I nie mam pojęcia czym to jest spowodowane. Może ktoś mi powiedzieć dlaczego nie widzi RmiServiceExporter?? Z góry dzieki za pomoc.

1

Masz podane - w classpath brakuje jara aop-alliance, i nie mozna znalezc klasy Aspect z tego pakietu. Chyba jasniejszy wyjatek byc nie mogl.

1

Sory, nie moze znalezc Advice.

1

nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice

naprawde tego nie widzisz czy udajesz?

0

Nie trzeba Od razu tak ostro dopiero zaczynam z frameworkiem spring. Ale dziekuje bardzo za odp.

1 użytkowników online, w tym zalogowanych: 0, gości: 1