Note that there are some explanatory texts on larger screens.

plurals
  1. PORight configuration for spring mvc app
    primarykey
    data
    text
    <p>I read this "It is a best practice to keep a clear separation between middle-tier services such as business logic components and data access classes (that are typically defined in the ApplicationContext) and web- related components such as controllers and view resolvers (that are defined in the WebApplicationContext per Dispatcher Servlet)."</p> <p>And decide configure my application like that 4 separate xml file </p> <p>applicationContext.xml</p> <pre><code>&lt;context:component-scan base-package="appname"&gt; &lt;context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/&gt; &lt;/context:component-scan&gt; </code></pre> <p>dao.xml</p> <pre><code>&lt;!-- MySQL JDBC Data Source--&gt; &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt; &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt; &lt;property name="url" value="jdbc:mysql://#{mysqlDbCredentials.hostname}:#{mysqlDbCredentials.port}/#{mysqlDbCredentials.name}"/&gt; &lt;property name="username" value="#{mysqlDbCredentials.username}"/&gt; &lt;property name="password" value="#{mysqlDbCredentials.password}"/&gt; &lt;/bean&gt; &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="persistenceUnitName" value="JpaPersistenceUnit" /&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="jpaVendorAdapter"&gt; &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt; &lt;property name="showSql" value="true"/&gt; &lt;property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"/&gt; &lt;/bean&gt; &lt;/property&gt; &lt;property name="jpaProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt; &lt;prop key="hibernate.showSql"&gt;true&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager"&gt; &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt; &lt;/bean&gt; &lt;tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/&gt; </code></pre> <p>and mvc-dispatcher-servlet.xml</p> <pre><code> &lt;mvc:annotation-driven /&gt; &lt;context:component-scan base-package="appname" use-default-filters="false"&gt; &lt;context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/&gt; &lt;/context:component-scan&gt; </code></pre> <p>web.xml(load spring context)</p> <pre><code> &lt;servlet&gt; &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt; &lt;servlet-class&gt; org.springframework.web.servlet.DispatcherServlet &lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt; /WEB-INF/spring/mvc-dispatcher-servlet.xml &lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt; &lt;url-pattern&gt;/spring/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;!-- Load spring beans definition files --&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt; /WEB-INF/spring/applicationContext.xml /WEB-INF/spring/security.xml /WEB-INF/spring/dao.xml &lt;/param-value&gt; &lt;/context-param&gt; </code></pre> <p>But I'm absolutly confused. 1)I don't understand how many context in this case I get.<br> 2)I want easy replace tx mode on aspectj (which work just in ome context as I know). But when I replace I get error with transation.</p> <p>Main problem that I want to have universal variant for both type of transaction Here I add <code>mode="aspectj"</code> and I have annotation like @Service, @Resourse, on concrete classes </p> <pre><code> &lt;tx:annotation-driven transaction-manager="transactionManager" mode="aspectj" proxy-target-class="true"/&gt; </code></pre> <p>All seems should work but I get next exception on <code>flush</code></p> <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827) at javax.servlet.http.HttpServlet.service(HttpServlet.java:575) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) at javax.servlet.http.HttpServlet.service(HttpServlet.java:668) at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1239) at [internal classes] at org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66) at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:194) at [internal classes] Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:993) at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-2) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) </code></pre> <p>Please, help me uderstand better</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload