Hi,

I have just experienced the same problem.
Using Kryo for object serialization my problem occured between serialization 
and deserialization.
In my case the problem is solved by setting the class loader for the serializer before and after serializazation.
    classLoader = Thread.currentThread().getContextClassLoader()
I am aware that Thread Context Class Loader is frowned upon in OSGi circles but it is the only way I have found to solve my use case.
You code is very different to my case but hoping this might provide a clue.

Paul Fraser

On 5/04/2020 3:07 pm, Jean-Baptiste Onofre wrote:
Hi

I guess it's specific for the way you deploy your bundles (using the deploy 
folder). If you do the same via bundle:* commands it should be fine right ?

Let me check if it?s not an issue with fileinstall. I don?t remember any issue 
there.

Regards
JB

Le 3 avr. 2020 à 15:56, Anton <antoxa...@list.ru.INVALID> a écrit :

Karaf version 4.2.4.

When I deploy bundles at first time - everything works as expected, but if I
remove bundles(from deploy directory) and do deploy them again(copy to
deploy directory), I will get "java.lang.ClassCastException: test.Test
cannot be cast to test.Test" error at runtime and a blueprint container
fail.
I suggest that error caused by using different classloaders but I can't
understand how to avoid it?
May be I have to use special karaf commands to undeploy/deploy?

Main question is - how to redeploy bundles without stopping the server?

Description. 3 bundles:

1. *datasource *- used for instantiation DataSource and put in a blueprint
container. There is no java code - blueprint.xml configuration only
```
...
<service interface="javax.sql.DataSource" ref="dataSource" />
...
```

2. *domain* - injects datasource and creates service which use mybatis
mapper. POJO also described here.

blueprint.xml:
```
<reference id="datasource" interface="javax.sql.DataSource"/>

<bean id="managerimpl" class="test.TestManagerImpl">
        <argument ref="datasource"/>
</bean>

<service id="testmanager" interface="test.TestManager" ref="managerimpl"/>
```

Service class:
```
public class TestManagerImpl implements TestManager {
    private final Mapper mapper;
    private final DataSource dataSource;

    public TestManagerImpl(DataSource dataSource) {
        this.dataSource = dataSource;
        this.mapper =
MybatisSqlSessionGetter.getSqlSessionMapperInstance(dataSource,
Mapper.class);
    }

    @Override
    public Test getTestById(String id) {
        return mapper.getById(id);
    }
        ...
}
```

POJO:
```
public class Test {
        private String id;
    private String name;
        ...
}       
```

3. *dependent *- injects service from domain bundle and use it for getting
POJO.

blueprint.xml:
```
<reference id="testmanager" interface="test.TestManager"/>

<bean id="dependentService" class="test.DependentService">
        <argument ref="testmanager"/>
</bean>
...
```

Service:
```
public class DependentService {
    private final TestManager manager;

    public DependentService(TestManager manager) {
        this.manager = manager;
        Test testById = manager.getTestById("uuid");        //
ClassCastException
    }
}
```



--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-Dev-f930721.html


Reply via email to