I have a Spring+SpringMVC demo, I can't understand how to use <mvc:annotation-driven/>, when I hava <context:component-scan base-package="com.jiehang.spring.controller" without <mvc:annotation-driven/> in spring-mvc.xml. The project can also run, if so, why do we need to write <mvc:annotation-driven/> in spring-mvc.xml ? Anyone can answer me, please. Thanks
web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
spring-mvc.xml:
<context:component-scan base-package="com.jiehang.spring.controller" />
<!-- <mvc:annotation-driven /> -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
spring.xml:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thinXXX" />
<property name="username" value="XXX" />
<property name="password" value="XXX" />
</bean>
<bean id="tsmCountsService" class="com.jiehang.spring.service.impl.TsmCountsServiceImpl">
<property name="tsmCountsDao" ref="tsmCountsDao" />
</bean>
<bean id="tsmCountsDao" class="com.jiehang.spring.dao.impl.TsmCountsDaoImpl">
<property name="dataSource" ref="dataSource" />
</bean>
Controller:
#Controller
public class FundController {
#Autowired
private TsmCountsService tsmCountsService;
public TsmCountsService getTsmCountsService() {
return tsmCountsService;
}
public void setTsmCountsService(TsmCountsService tsmCountsService) {
this.tsmCountsService = tsmCountsService;
}
#RequestMapping("/queryFund")
public ModelAndView queryFundByFundId() {
List<TsmCounts> funds = tsmCountsService.queryUser();
System.out.println(funds);
return null;
}
}
When I input url: http://localhost:8080/TestSpringmvc/queryFund, I can get output result. So, It doesn't matter if you don't write <mvc:annotation-driven />.
<mvc:annotation-driven /> provides support for annotation-driven MVC controllers (like #RequestMapping and #Controller) although it is the default behaviour, along with this it adds support for validation via #Valid and message body with #RequestBody/ResponseBody.
Related
I'm working on a Spring-framework project of my own. When I just ran the project, the result keeps showing 404 error, without any other error message. How can I find where the error occurred?
I have tried printing a message at the start of the Controller, and it wasn't printed. So I guess that the error occurs before the Controller.
This is a part of applicationContext.xml file:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis-config.xml" />
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:mappers/**/*.xml" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.my.test" />
</bean>
<mybatis:scan base-package="reserving" />
This is a part of dispatcher-servlet.xml file:
<mvc:annotation-driven />
<mvc:default-servlet-handler />
<mvc:view-resolvers>
<mvc:jsp prefix="/WEB-INF/views/" />
</mvc:view-resolvers>
<context:component-scan base-package="reserving" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
This is a part of web.xml file:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- <load-on-startup>1</load-on-startup>-->
<init-param>
<param-name>contextConfiguration</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I expect the result page shows a json Query that the Controller returns, but only 404 error occurs, before even going inside the Controller.
This question already has answers here:
Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request with URI [...] in DispatcherServlet"?
(13 answers)
Closed 6 years ago.
I tried all the trails posted in internet mainly in stackoverflow but coudn't find the exact solution of my application problem.
Please don't mark this as duplicate because warning might be the duplicate but version or something else is causing which is not duplicate here i.e the same answers are no working for me
Warning i'm getting:
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI in DispatcherServlet with name 'appServlet'
Code of my application:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
servlet-context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<!-- <annotation-driven /> -->
<!-- <context:annotation-config/> -->
<mvc:annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<!-- <resources mapping="/resources/**" location="/resources/" /> -->
<!-- Resolves views selected for rendering by #Controllers to .jsp resources
in the /WEB-INF/views directory -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://localhost:3306/TestDB" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<!-- Hibernate 4 SessionFactory Bean definition -->
<bean id="hibernate4AnnotatedSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.mahender.web.model.Person</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="personDAO" class="com.mahender.web.DAO.PersonDAOImpl">
<property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
</bean>
<bean id="personService" class="com.mahender.web.service.PersonServiceImpl">
<property name="personDAO" ref="personDAO"></property>
</bean>
<context:component-scan base-package="com.mahender.web" />
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
</bean>
Snippet of my Controller(not all the code provided i think this is enough to find the problem)
#RequestMapping(value = "/app")
#Controller
public class PersonController {
private PersonService personService;
#Autowired(required=true)
#Qualifier(value="personService")
public void setPersonService(PersonService ps){
this.personService = ps;
}
#RequestMapping(value = "/persons", method = RequestMethod.GET)
public String listPersons(Model model) {
model.addAttribute("person", new Person());
model.addAttribute("listPersons", this.personService.listPersons());
return "person";
}
and the jsp snippet of code is:
person.jsp
<c:url var="addAction" value="/person/add" ></c:url>
<form:form action="${addAction}" commandName="person">
You need to add this on your code.
model.setViewName("person");
model.addAttribute("person", new Person());
and also make sure your .jsp file is inside /views folder
Your requested action is not mapped properly in controller try to changed it to app/person/add
I got this error:
javax.servlet.ServletException: Could not resolve view with name 'home' in servlet with name 'appServlet'
This is my servlet-context.jsp
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<import resource="classpath:di-context.xml"/>
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- Register the welcome.properties -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages"/>
<property name="defaultEncoding" value="UTF-8"/>
</bean>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang"/>
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en_US"/>
</bean>
<!--class="org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver" />-->
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
<property name="interceptors">
<ref bean="localeChangeInterceptor"/>
</property>
</bean>
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
</mvc:interceptors>
<!-- <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="WEB-INF/classes/messages" /> </bean> -->
<!-- Enables the Spring MVC #Controller programming model -->
<mvc:annotation-driven/>
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<mvc:resources mapping="/resources/**" location="/resources/"/>
<context:component-scan base-package="ru.blogspot.feomatr.controller"/>
<!-- Resolves views selected for rendering by #Controllers to .jsp resources
in the /WEB-INF/views directory -->
<!-- beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" -->
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"/>
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/layouts/layouts.xml</value>
<!-- Scan views directory for tiles configuration -->
<value>/WEB-INF/views/**/views.xml</value>
</list>
</property>
</bean>
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
</beans>
This is my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml
/WEB-INF/spring/security.xml
classpath:di-context.xml
</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
My home
#RequestMapping(value = {"/home", "/"}, method = RequestMethod.GET)
public String showHome(Model model) {
log.info("showHome");
return "home";
}
And Yes I have the file home.jsp in the path src/main/webapp/WEB-INF/views
I'm not able to fixed it, someone can help me please?
Change your request mapping like this..
#RequestMapping(value = "/home", method = RequestMethod.GET)
public String showHome(Model model) {
log.info("showHome");
return "home";
}
and add this in your spring-servlet.xml..
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
I think I crashed my setup because my mapping isn't working any more and I don't know why. Here are my web.xml, applicationContext.xml payment-servlet.xml and payment.beans.xml.
**web.xml**
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- Add Support for Spring -->
<!-- Default applicationContext location: /WEB-INF/applicationContext.xml -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- exposes the request to the current thread -->
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- springapp payment servlet -->
<servlet>
<servlet-name>payment</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<!-- <param-value>classpath:/spring/servlet/payment-servlet.xml</param-value> -->
<param-value>file:**/webapp/META-INF/spring/servlet/payment-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>payment</servlet-name>
<url-pattern>/payment/*</url-pattern>
<url-pattern>/paymentExternalData</url-pattern>
<url-pattern>/paymentInternalData</url-pattern>
</servlet-mapping>
<!-- Welcome files -->
<welcome-file-list>
<welcome-file>payment.jsp</welcome-file>
<welcome-file>payment.html</welcome-file>
</welcome-file-list>
</web-app>
**applicationContext.xml**
<context:annotation-config />
<!-- payment servlet
<import resource="classpath:/spring/payment.beans.xml"/> -->
<import resource="file:**/webapp/META-INF/spring/payment.beans.xml"/>
<!-- Auto scan the components -->
<context:component-scan
base-package="com.app.payment.model.PaymentUser" />
**payment-servlet**
<!-- Auto scan the components -->
<context:component-scan base-package="at.dt_i.primesign.payment" />
<!-- Payment controller -->
<bean class="at.dt_i.primesign.payment.controller.PaymentController">
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!-- PropertyPlaceholderConfigurer
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" depends-on="configuration">
<property name="properties" ref="configuration" />
</bean> -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/configuration.properties</value>
</property>
</bean>
**payment.beans.xml**
<context:annotation-config />
<tx:annotation-driven />
<bean id="paymentDao" class="com.app.payment.model.PaymentDAOImpl" />
<bean id="paymentService" class="com.app.payment.PaymentServiceImpl" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${database.driverClassName}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
</bean>
<bean id="paymentTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="paymentEntityManagerFactory" />
</bean>
<!-- -->
<bean id="paymentJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="${paymentJpaVendorAdapter.generateDdl}" />
<property name="databasePlatform" value="${paymentJpaVendorAdapter.databasePlatform}" />
</bean>
<bean id="paymentEntityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="profileDataSource" />
<property name="jpaVendorAdapter" ref="paymentJpaVendorAdapter" />
<property name="persistenceUnitName" value="payment" />
</bean>
My first question: Is my structure right or is there a better solution.
the main goal is to operate with to controller methods /paymentInternalData and /paymentExternalData. But I think the dispatchServlet loads something different because the mapping is not working it only shows the welcome page. but not the 2 sub pages.
I know this is mainly code but I'm not sure what to post, so I posted everything. hopefully anybody can help.
I think your Url-pattern for servlet is correct :
<servlet-mapping>
<servlet-name>payment</servlet-name>
<url-pattern>/payment/*</url-pattern>
<url-pattern>/paymentExternalData</url-pattern>
<url-pattern>/paymentInternalData</url-pattern>
</servlet-mapping>
But the
file:**/webapp/META-INF/spring/servlet/payment-servlet.xml
is not able to load the payment-servlet.xml file.
If your META-INF is under webapp directory then you can do this :
<init-param>
<param-name>contextConfigLocation</param-name>
<!-- <param-value>classpath:/spring/servlet/payment-servlet.xml</param-value> -->
<param-value>/META-INF/spring/servlet/payment-servlet.xml</param-value>
</init-param>
or
Remove the init-param block and move payment-servlet.xml under webapp/WEB-INF/ directory where web.xml present.
i am new to Spring and hibernate and i am stuck at this problem. i have been searching around for a fix but although there are a lot of questions on this, they do not seem to solve my problem. i am using spring 3.1.0 with hibernate 3.6.9 and making a web application with using spring mvc. After a lot of looking around, i managed to solve it with the following config
web.xml
<listener>
<description>Spring context loader</description>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
applicationContext.xml
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- Enables the Spring MVC #Controller programming model -->
<mvc:annotation-driven />
<context:annotation-config/>
<!-- Scans within the base package of the application for #Components to
configure as beans -->
<!-- #Controller, #Service, #Configuration, etc. -->
<context:component-scan base-package="com.emumba.cricketcalendar" />
<import resource="hibernate-context.xml"/>
hibernate-context.xml
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.emumba.cricketcalendar.domain.Match</value>
<value>com.emumba.cricketcalendar.domain.Ground</value>
<value>com.emumba.cricketcalendar.domain.Umpire</value>
<value>com.emumba.cricketcalendar.domain.Country</value>
<value>com.emumba.cricketcalendar.domain.CricketStatus</value>
<value>com.emumba.cricketcalendar.domain.Series</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="dataSource" ref="dataSource" />
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
And then i put the #Transactional on my service and this exception was gone. But then my autowiring stops working, the autowired annotation doesn't work and beans with autowired properties start throwing exception. i remove the #transactional annotation from my service and it again starts working but the "no hibernate session bound to thread " exception returns
So i am really confused , any help would be greatly appreciated
EDIT Service Code
#Service(value="calendarManager")
public class CalendarMangerImpl implements CalendarManager {
#Autowired
#Qualifier("matchDao")
public MatchDaoHibernate matchDao;
#Override
public List<Match> getAllMatches() {
List<Match> matches=new ArrayList<Match>();
matches=matchDao.findAll();
return matches;
}
}
Use the service class with reference to its interface and not the actual class as spring uses interface based proxies by default
Spring AOP defaults to using standard J2SE dynamic proxies for AOP proxies. This enables
any interface (or set of interfaces) to be proxied.
I will suggest first go through this simple example clear all the concepts. It will help you in future as well.