TransaktionManager OSGi

G

Gast2

Gast
Ich hab einen TransaktionManager als OSGi Service registriert. Damit ich im business bundle die Transaktionen eröffnen kann wenn ich im bean eine init methode angebe kann diese keine Transaktion aufmachen?! Ist das normal hab in der Doku dazu nichts gefunden oder etwas übersehen?

Wenn ich es jedoch im gleichen Bundle das mache ist das kein Problem

Wenn ich den Service und die Methode normal aufrufe gibts es auch keinerlei Probleme die Transaktion wird sauber geöffnet

Java:
public class PersonServiceImpl implements PersonService{

	@Autowired
	private PersonDao personDao;
	
	@Transactional(propagation=Propagation.REQUIRED)
	public Person consume() {
		return personDao.insert(person);
}

}
osgi.xml
[XML]
<osgi:reference id="transactionManager" interface="org.springframework.transaction.support.ResourceTransactionManager"></osgi:reference>
<osgi:reference id="personDaoRef" interface="org.java.forum.sample.dao.PersonDao"></osgi:reference>
[/XML]
context.xml
[XML]
<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
Index of /schema/context http://www.springframework.org/schema/context/spring-context.xsd
Index of /schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

<context:annotation-config />
<tx:annotation-driven transaction-manager="transactionManager" />

<bean id="personService" class="org.java.forum.sample.business.internal.PersonServiceImpl" init-method="consume">

</bean>

</beans>
[/XML]


DAO

Java:
public class DefaultPersonDao implements PersonDao {
	@PersistenceContext
	private EntityManager entityManager;
	
	@Override
	@Transactional(propagation=Propagation.MANDATORY)
	public Person insert(Person person) {
		entityManager.merge(person);
	}
	
	@Transactional(propagation=Propagation.REQUIRED)
	public void init() {
		Person person = new Person();
		person.setName("Name");
		person.setSurname("Test");
		insert(person);
	}

}

osgi xml
[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:eek:sgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
Index of /schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.2.xsd">



<osgi:reference id="dataSourceRef" interface="javax.sql.DataSource" cardinality="1..1" filter="(name=h2DataSource)"/>

<osgi:service id="transactionManagerService" ref="transactionManager" interface="org.springframework.transaction.support.ResourceTransactionManager"></osgi:service>
<osgi:service id="personDaoService" ref="personDao" interface="org.java.forum.sample.dao.PersonDao"></osgi:service>



</beans>
[/XML]

context.xml
[XML]
<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"></property>
</bean>

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"></bean>

<!-- DAO -->

<bean id="personDao" class="org.java.forum.sample.dao.internal.DefaultPersonDao" init-method="init"></bean>

</beans>
[/XML]
 
G

Gelöschtes Mitglied 5909

Gast
Ich bin mir nicht ganz sicher ob ich dich verstanden habe.

taucht das nur dadurch auf?

[xml]
init-method="init">
[/xml]

und wenn du sie selber aufrust gehts oder?

Ich tippe mal drauf, dass der TXM noch nicht da ist, wenn der context hochgefahren ist.

Setze mal das startlevel des bundles, das den TXM veröffentlicht auf mindestens eins höher als das des TXM Consumers.

Ich tippe außerdem dass das dependency waiting bei Spring AOP nicht 100%ig funzt.

Alternativ kannst du auch das TXM consumer bundle einfach mal neu starten
 
G

Gast2

Gast
Jop kommt genau davon ... Und im gleichen Bundle klappt es auch. Denke auch das der context sich zu spät aktualisiert
Wenn ich es selber aufrufe funktioniert es einwandfrei ja hab bis jetzt alle startlevel auf default. Aber muss ich mal versuchen auf was soll ich sie stellen 3 und 4?
 
G

Gelöschtes Mitglied 5909

Gast
default ist glaub ich 4 (steht aber auch oben im run-dialog), also stell sie mal auf 5 oder so :)
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
M Spring DM: Problem mit Tomcat als OSGI-Service Application Tier 1

Ähnliche Java Themen

Neue Themen


Oben