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