java.lang.IllegalStateException: No Hibernate Session bound to thread - java

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.

Related

springmvc <mvc:annotation-driven /> and <context:component-scan base-package="" />

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.

Spring 4.x and hibernate 4.x basic CRUD application getting warning No mapping found for HTTP request with URI [duplicate]

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

Spring MVC Url-Pattern DispatchServlet

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.

Spring MVC 3 I18N/MessageSource not working

I am trying to configure internazionalization in Spring MVC (using changing of locales via links), however, it doesn't seem to be working at all: default locale is always ru for some reason, though default is set to en, they are not changing using links, spring messages are displayed empty regardless of the chosen locale (messages_de, messages_en and messages_ru.properties DO exist at classpath (src/main/resources)). They contain e.g.
label.test=Russian
and i refer to them as
<spring:message code="label.test" />
in my JSPs. They are not being displayed like that.
I take it as even messageSource is not found, even though there are no errors or warnings. I'd really appreciate any help as I'm trying to figure it out for really long time. Apparently, I've missed some details, but I definitely can't catch the problem. Here are my configuration files (or most relevant parts).
root-context.xml
<context:component-scan base-package="... .dao" />
<context:component-scan base-package="... .service" />
<import resource="data.xml" />
<import resource="security.xml" />
mvc-dispatcher-servlet.xml
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="sitelocale" />
</bean>
</mvc:interceptors>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en" />
</bean>
data.xml
<!-- Transaction Manager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<!-- //////////////////////////////////////////////////////////////////////////
" -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.databaseurl}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- ////////////////////////////////////////////////////////////////////////// -->
<!-- Hibernate SessionFactory configuration -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.tsystems.javaschool.kts.domain" />
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
</props>
</property>
</bean>
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring MVC -->
<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/mvc-dispatcher-servlet.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>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<!-- Spring Security -->
<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>
You don't need to prefix the basename value with "classpath:", try to change it as follows:
<property name="basename" value="messages" />
Adding the following should allow you to change the lang with a URL parameter named "lang" (i.e. lang=en). This will allow you to override browser default settings and explicitly declare the language in use.
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<ref bean="localeChangeInterceptor" />
</property>
</bean>
Also, ensure in the deployed webapp that the message files are located under WEB-INF/classes/ if you are going to use classpath:messages as a basename.
Also check if you add this at the top
<%# page contentType="text/html;charset=UTF-8" %>

Deploying a spring-mvc application failed

I am working with spring-mvc with hibernate, and I have deployed my application on go daddy server, when I open any html file it works well, But on opening a jsp file, gives me a 404 file not found error. Please any one can help me with the problem...?
I m using Spring 3.0,
Jdk 1.7.0_04,
apache-tomcat 6.0.32
The web.xml I'm using is
web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>seekersworkroom</display-name>
<welcome-file-list>
<welcome-file>/view/Index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>imageupload</servlet-name>
<servlet-class>com.seekersworkroom.controller.imageuploadController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>imageupload</servlet-name>
<url-pattern>/imageupload.htm</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Userimageupload</servlet-name>
<servlet-class>com.seekersworkroom.controller.UserimageuploadController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Userimageupload</servlet-name>
<url-pattern>/Userimageupload.htm</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>seekersworkroom</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>seekersworkroom</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>seekersworkroom-servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/seekersworkroom-servlet.xml,
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<!-- Spring Security -->
<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>
The welcome doesnot dispaly index.jsp file but if the same is replaced by index.html it shows this file. And by opening any url eith .jsp extension it shows 404 error.
seekersworkroom-servlet:
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean name="/login/*.htm" id="AdminprofileController" class="com.seekersworkroom.controller.AdminprofileController">
</bean>
<bean name="/Index/*.htm" id="IndexController" class="com.seekersworkroom.controller.IndexController">
<property name="indexDAO" ref="IndexDAO" />
<property name="skillsaddedDAO" ref="SkillsaddedDAO" />
<property name="skillsDAO" ref="SkillsDAO"></property>
<property name="userDAO" ref="UserDAO" />
<property name="acountryDAO" ref="acountryDAO" />
<property name="bregDAO" ref="BregistrationDAO" />
<property name="cregistrationDAO" ref="CregistrationDAO" />
<property name="ccontactDAO" ref="CcontactDAO" />
<property name="caddressDAO" ref="CaddressDAO" />
<property name="asubcategoryDAO" ref="AsubcategoryDAO" />
<property name="cportfolioDAO" ref="CportfolioDAO" />
<property name="keywordDAO" ref="KeywordDAO" />
<property name="bcreatejobDAO" ref="BcreatejobDAO" />
<property name="messageDAO" ref="messageDAO"></property>
<property name="userimageDAO" ref="UserimageDAO" />
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/view/" p:suffix=".jsp" />
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" >
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/skw"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="mappingResources">
<list>
<value>com/seekersworkroom/VO/User.hbm.xml</value>
<value>com/seekersworkroom/VO/buyerregistration.hbm.xml</value>
<value>com/seekersworkroom/VO/contractorregistration.hbm.xml</value>
<value>com/seekersworkroom/VO/Contractorcontact.hbm.xml</value>
<value>com/seekersworkroom/VO/Contractoraddress.hbm.xml</value>
<value>com/seekersworkroom/VO/Contractorkeyword.hbm.xml</value>
<value>com/seekersworkroom/VO/Userimage.hbm.xml</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">update</prop>
</props>
</property>
</bean>
<bean id="acountryDAO" class="com.seekersworkroom.DAO.AcountryDAO" >
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
<bean id="AcategoriesDAO" class="com.seekersworkroom.DAO.AcategoriesDAO" >
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
</beans>
This is the servlet file in which the annotaions are used to cal to particular controllers.
This servlet contains the beans through which the request is redirected to particular controllers.
But the main problem is jsp file is not working only...
What can I do in web.xml so that it allows me to access the jsp file on server side??
Is that the problem with Spring framework or the web.xml file is missing something???
I assume the jsp you are accessing is outside of your WEB-INF folder. In such cases, use <mvc:resources mapping="/static/**" location="/" /> in your seekersworkroom-servlet.xml; and access the jsp using url http://yourdomain/static/yourjspname.jsp.
Also, you may not need to protect your static resources; So, use
<http pattern="/static/**" security="none" xmlns="http://www.springframework.org/schema/security"/> in your spring security configuration file

Categories

Resources