<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=kalradeepak" rel="nofollow">Deepak Kalra</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-586?redirect=false" rel="nofollow">SPR-586</a></strong> and commented</p>
<p dir="auto">Hi,</p>
<p dir="auto">I am in the process of designing the architecture using Spring Framwork.<br>
We are looking for the solution as follows</p>
<p dir="auto">Client calls the EJB Layer and EJB Layer initiates the transaction management i.e. Stateless Session Bean with CMT. Stateless Session Bean in turn calls the Spring Service Layer Which in turn calls the POJO i.e. Hibernate.</p>
<p dir="auto">My Question is If I will set the Session Beam Transaction as REQUIRES_NEW i.e. JTA Application Server and Service Layer of Spring Framework will be using JTATransaction and method is having PROPAGATION as Required Transaction.</p>
<p dir="auto">&lt;bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;<br>
&lt;property name="jndiName"&gt;&lt;value&gt;jdbc/jpetstore&lt;/value&gt;&lt;/property&gt;<br>
&lt;/bean&gt;<br>
&lt;bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"&gt;<br>
&lt;property name="dataSource"&gt;&lt;ref local="dataSource"/&gt;&lt;/property&gt;<br>
&lt;property name="mappingResources"&gt;<br>
&lt;value&gt;org/springframework/samples/petclinic/hibernate/petclinic.hbm.xml&lt;/value&gt;<br>
&lt;/property&gt;<br>
&lt;property name="hibernateProperties"&gt;<br>
&lt;props&gt;<br>
&lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt;<br>
&lt;/props&gt;<br>
&lt;/property&gt;<br>
&lt;/bean&gt;</p>
<p dir="auto">&lt;bean id="transactionManager"<br>
class="org.springframework.transaction.jta.JtaTransactionManager"/&gt;</p>
<p dir="auto">Will this work  architecture work. As EJB has initiated the transaction. Will it possible that POJO method works in the same transaction or Not. I will appreciate If you guys can help me out.</p>
<p dir="auto">Kind Regards<br>
Deepak</p>
<hr>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398053845" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/5318" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/5318/hovercard" href="https://github.com/spring-projects/spring-framework/issues/5318">#5318</a> Integration of EJB CMT with Spring Framework (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=urubatan" rel="nofollow">Rodrigo Urubatan Ferreira Jardim</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-1987?redirect=false" rel="nofollow">SPR-1987</a></strong> and commented</p>
<p dir="auto">I think some bean definitions are just configuration, as the Data Source, Transaction Manager, Mail Server, ...<br>
but most of then are the application code, and not configuration.<br>
for the seccond case, I think it would be very easy and clean, to register it on the application with annotations, because it would use a lot less code than the XML approach, and this beans registrations (like my application DAOs, or my Spring MVC controllers), does not change during the life time of any application.<br>
for this to be reached it would be necessary to scan the classpath for the annotated classes.</p>
<p dir="auto">I have wrote a litle bouch of classes that make the application context behave exaclty this way, enabling it to use bean registration by annotations.<br>
please consider including it in spring framework as an optional extension.</p>
<p dir="auto">I`m not sure the application way I did it (creating another application context class) is the best one, but it is an idea of implementation for it :D</p>
<p dir="auto">the code I have wrote is atacched.<br>
what it does right now is:</p>
<ol dir="auto">
<li><code class="notranslate">@Bean</code> - equals to &lt;bean&gt;
<ul dir="auto">
<li>autoWire (NO, BY_NAME, BY_TYPE, INHERITED)</li>
<li>dependencyCheck</li>
<li>destroyMethod</li>
<li>factoryMethod</li>
<li>initMethod</li>
<li>lazy</li>
<li>name</li>
<li>scope (APPLICATION, REQUEST, SESSION) - short cut to aop:scope</li>
<li>singleton</li>
</ul>
</li>
<li><code class="notranslate">@UrlMapping</code> - attaches the bean to a URL using an bean factor post processor (AnnotationHandlerMaping)</li>
<li><code class="notranslate">@UrlMappings</code> - enables multiple UrlMappings per bean</li>
<li><code class="notranslate">@Property</code></li>
<li><code class="notranslate">@ConstructorArgs</code></li>
</ol>
<p dir="auto">in the code, there is an example applicationContext.xml that enables WebServices using JSR 181 webservices through xfire/spring integration, and has already a propertyPlaceholderConfigurer.</p>
<p dir="auto">the annotation scan, for now scans every directory/jar in the classpath, that contains a file names to.properties in the root, and the propertyPlaceholderConfigurer uses this files too.</p>
<p dir="auto">with this jar, I was able to define only a datasource, transaction manager,sessionFactory,tx:annotation-driven,and a defaultViewResolver<br>
and write all the rest of my application without touching in a XML file.<br>
this way, all I need to know about my beans was in the bean code.</p>
<p dir="auto">the installation of it is preaty clean too:</p>
<p dir="auto">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</p>
<p dir="auto">&lt;web-app id="WebApp_ID" version="2.4"<br>
xmlns="<a href="http://java.sun.com/xml/ns/j2ee" rel="nofollow">http://java.sun.com/xml/ns/j2ee</a>"<br>
xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" rel="nofollow">http://www.w3.org/2001/XMLSchema-instance</a>"<br>
xsi:schemaLocation="<a href="http://java.sun.com/xml/ns/j2ee" rel="nofollow">http://java.sun.com/xml/ns/j2ee</a> <a href="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd%22%3E" rel="nofollow">http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;</a><br>
&lt;display-name&gt;TO - Novo Site&lt;/display-name&gt;<br>
&lt;context-param&gt;<br>
&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;<br>
&lt;param-value&gt;classpath*:applicationContext.xml&lt;/param-value&gt;<br>
&lt;/context-param&gt;<br>
&lt;context-param&gt;<br>
&lt;param-name&gt;contextClass&lt;/param-name&gt;<br>
&lt;param-value&gt;<br>
br.com.techoffice.spring.web.TOAnnotationXmlWebApplicationContext<br>
&lt;/param-value&gt;<br>
&lt;/context-param&gt;<br>
&lt;listener&gt;<br>
&lt;listener-class&gt;<br>
org.springframework.web.context.ContextLoaderListener<br>
&lt;/listener-class&gt;<br>
&lt;/listener&gt;<br>
&lt;filter&gt;<br>
&lt;filter-name&gt;requestContext&lt;/filter-name&gt;<br>
&lt;filter-class&gt;<br>
org.springframework.web.filter.RequestContextFilter<br>
&lt;/filter-class&gt;<br>
&lt;/filter&gt;<br>
&lt;filter-mapping&gt;<br>
&lt;filter-name&gt;requestContext&lt;/filter-name&gt;<br>
&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br>
&lt;/filter-mapping&gt;<br>
&lt;servlet&gt;<br>
&lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;<br>
&lt;servlet-class&gt;<br>
org.springframework.web.servlet.DispatcherServlet<br>
&lt;/servlet-class&gt;<br>
&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;<br>
&lt;/servlet&gt;<br>
&lt;servlet-mapping&gt;<br>
&lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;<br>
&lt;url-pattern&gt;*.to&lt;/url-pattern&gt;<br>
&lt;/servlet-mapping&gt;<br>
&lt;servlet-mapping&gt;<br>
&lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;<br>
&lt;url-pattern&gt;/web/*&lt;/url-pattern&gt;<br>
&lt;/servlet-mapping&gt;<br>
&lt;/web-app&gt;</p>
<p dir="auto">a blank dispatcher-servlet.xml (does this is really needed? what if I want all my configuration to be application-wide, I really need to create a xml file to each servlet, or in this case to the only servlet I have?)</p>
<p dir="auto">again, please consider it as an optional module for spring framework.<br>
and thanks for the great framework, it has saved a few of my projects in clients in the last 2 years.</p>
<hr>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/11617/spring-annotations.zip" rel="nofollow">spring-annotations.zip</a> (<em>13.03 kB</em>)</li>
</ul>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398078047" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/8169" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/8169/hovercard" href="https://github.com/spring-projects/spring-framework/issues/8169">#8169</a> Enable the definition of beans in the application context using annotations instead of XML, but do it right (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto">4 votes, 5 watchers</p>