Servlet cannot be resolved - java

I am working on a Spring MVC project which uses hibernate with postgreSQL for saving data.
I have a JSP file, which calls the action to "/user/add" residing in controller. But the error I get is the servlet cannot be resolved. I have added the jar in libraries in the project structure. I am posting the controller and JSP code here. Kindly have a look.
user.jsp
<c:url var="addAction" value="/user/add"> </c:url>
<form:form action="${addAction}" commandName="user">
<table>
<c:if test="${!empty user.first_Name}">
<tr>
<td>
<form:label path="id">
<spring:message text="UserID:"/>
</form:label>
</td>
<td>
<form:input path="id" readonly="true" size="8" disabled="true" />
<form:hidden path="id" />
</td>
</tr>
</c:if>
UserController
#RequestMapping(value="/user/add",method = RequestMethod.POST)
public String addPerson(#ModelAttribute("user") User p){
if(p.getId() == 0){
this.userService.addUser(p);
} else {
this.userService.updateUser(p);
}
return "redirect:/users";
}
Catalina.out
Sep 17, 2014 11:44:55 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /home/akshay/apache-tomcat/webapps/WirTauschen-1.0-SNAPSHOT.war
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Wed Sep 17 11:44:56 CEST 2014]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/root-context.xml]
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 96 ms
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'appServlet-servlet': startup date [Wed Sep 17 11:44:56 CEST 2014]; parent: Root WebApplicationContext
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/users],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.WirTauschen.UserController.listUsers(org.springframework.ui.Model)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/user/add],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.WirTauschen.UserController.addPerson(com.WirTauschen.model.User)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/edit/{id}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.WirTauschen.UserController.editPerson(int,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/remove/{id}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.WirTauschen.UserController.removeUser(int,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
INFO : org.hibernate.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
INFO : org.hibernate.Version - HHH000412: Hibernate Core {4.3.6.Final}
INFO : org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
INFO : org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist
INFO : org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
INFO : org.hibernate.engine.jdbc.internal.LobCreatorBuilder - HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
INFO : org.hibernate.engine.transaction.internal.TransactionFactoryInitiator - HHH000399: Using default transaction strategy (direct JDBC transactions)
INFO : org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory - HHH000397: Using ASTQueryTranslatorFactory
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization completed in 914 ms
Sep 17, 2014 11:44:57 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /home/akshay/apache-tomcat/webapps/WirTauschen-1.0-SNAPSHOT.war has finished in 1,761 ms
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/WirTauschen%2D1.0%2DSNAPSHOT/] in DispatcherServlet with name 'appServlet'
Hibernate: select user0_.id as id1_0_, user0_.email as email2_0_, user0_.first_Name as first_Na3_0_, user0_.last_name as last_nam4_0_, user0_.password as password5_0_ from wirtausch2 user0_
Hibernate: insert into wirtausch2 (email, first_Name, last_name, password) values (?, ?, ?, ?)
WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 23502
ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: null value in column "id" violates not-null constraint
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Closing WebApplicationContext for namespace 'appServlet-servlet': startup date [Wed Sep 17 11:44:56 CEST 2014]; parent: Root WebApplicationContext
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Closing Root WebApplicationContext: startup date [Wed Sep 17 11:44:56 CEST 2014]; root of context hierarchy
Kindly let me know. Thank you.

Edit : my mistake, see below
You add the context path twice.
<c:url var="addAction" value="/user/add"> </c:url> puts the full path (context path + servlet path) in addAction, and you use it in <form:form action=...>, which also adds the context path.
You should use instead :
<form:form action="/user/add" commandName="user" method="POST">
You only need to use <c:url .../> if you use the path in a link <a href="${addAction}"...>
I make confusion with the spring library for Velocity that I am used to and which directly knows about the servlet context. In true JSP, you have to use <c:url ...> to get the correct action url.
I really need the stacktrace to help you : I could do some tests and the problem is not where I thought.

Related

Tomcat fails to start and crash randomly

I need some help. Last week we've migrated to Git (and for now we're using fork as client) and I've started a new workspace into sts. Everything it's working well but I don't know why, completly randomly, tomcat crash, usually after a refresh (refreshed by me or by itself, without any command). I don't have the "build automatically" option actived of course, but still, it's like tomcat refresh itself and crash.
The starting log error is the following (first line, classloaderbase):
org.apache.catalina.loader.WebappClassLoaderBase modified
GRAVE: Resource '/WEB-INF/classes//it/sabacom/domain/amministrativo/IncassoDettaglioPartitario.class' is missing
lug 15, 2019 12:16:54 PM org.apache.catalina.core.StandardContext reload
INFORMAZIONI: Reloading Context with name [/easyplanweb] has started
12:16:54.166 INFO - - URL= - org.springframework.web.context.support.XmlWebApplicationContext.() - Closing Root WebApplicationContext: startup date [Mon Jul 15 11:52:47 CEST 2019]; parent: Root WebApplicationContext
lug 15, 2019 12:16:54 PM org.apache.catalina.core.ApplicationContext log
INFORMAZIONI: Destroying Spring FrameworkServlet 'reports'
12:16:54.180 INFO - - URL= - org.springframework.web.context.support.XmlWebApplicationContext.() - Closing WebApplicationContext for namespace 'reports-servlet': startup date [Mon Jul 15 11:52:48 CEST 2019]; parent: Root WebApplicationContext
lug 15, 2019 12:16:54 PM org.apache.catalina.core.ApplicationContext log
INFORMAZIONI: Destroying Spring FrameworkServlet 'magazzino'
12:16:54.182 INFO - - URL= - org.springframework.web.context.support.XmlWebApplicationContext.() - Closing WebApplicationContext for namespace 'magazzino-servlet': startup date [Mon Jul 15 11:52:48 CEST 2019]; parent: Root WebApplicationContext
lug 15, 2019 12:16:54 PM org.apache.catalina.core.ApplicationContext log
INFORMAZIONI: Destroying Spring FrameworkServlet 'rest'
12:16:54.184 INFO - - URL= - org.springframework.web.context.support.XmlWebApplicationContext.() - Closing WebApplicationContext for namespace 'rest-servlet': startup date [Mon Jul 15 11:52:48 CEST 2019]; parent: Root WebApplicationContext
lug 15, 2019 12:16:54 PM org.apache.catalina.core.ApplicationContext log
INFORMAZIONI: Destroying Spring FrameworkServlet 'maps'
Does someone has some ideas? Thank you!

Apache tomcat issue with Eclipse dynamic web module 3.0

I created Spring MVC project with default configurations it was working/running on the server but when I changed Project Facets to J2EE 6 as following :
now when I run the project I get following message
UPDATE
Please see this project structure :
Controller.java is
#Controller
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
/**
* Simply selects the home view to render by returning its name.
*/
#RequestMapping(method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Welcome home! The client locale is {}.", locale);
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate );
return "home";
}
}
New Console out put without any error is :
Jun 20, 2015 6:33:38 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Sat Jun 20 18:33:38 PKT 2015]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/root-context.xml]
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#1a8f100: defining beans []; root of factory hierarchy
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 893 ms
Jun 20, 2015 6:33:39 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'appServlet'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'appServlet-servlet': startup date [Sat Jun 20 18:33:39 PKT 2015]; parent: Root WebApplicationContext
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#1c047f0: defining beans [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.web.servlet.view.InternalResourceViewResolver#0,homeController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#1a8f100
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String home.com.web.HomeController.home(java.util.Locale,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization completed in 2619 ms
with this at http://localhost:8080 also shows HTTP Status 404 Any hint in this case? What should I do?
Your problem has nothing to do with eclipse or dynamic web modules in eclipse, except there exists more than one problem. You have a general problem in your spring configuration.
You are trying to map '/' via RequestMapping - that does not work even in in Spring MVC 4.1.6 - independent of eclipse or dynamic web module.
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
- Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}"
onto public java.lang.String sd.sdse.dsdds.HomeController.home(java.util.Locale,org.springframework.ui.Model)
There are more similar questions about how define a mapping to the context root in in the spring.io forum like "#RequestMapping pointing to /"
You archive this by mapping the Spring Dispatcher Servlet to "/" not "/*"
and by removing the explicit mapping to "/" from your #RequestMapping annotations.
The Project you've shared is not the one which generates the log output. The project not even starts a SpringContext when deployed and executed on Tomcat.
To start the SpringContext you'll either have to configure the ContextLoadListener and / or DispatcherServlet in the web.xml
like here:
<display-name>Home</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/servlet-config.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></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>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Or you need a class that implements the WebApplicationInitializer interface like this one:
public class WebAppInitializer implements WebApplicationInitializer {
#Override
public void onStartup(ServletContext context) {
XmlWebApplicationContext rootContext =
new XmlWebApplicationContext();
rootContext.setConfigLocation("/WEB-INF/spring/root-context.xml");
context.addListener(new ContextLoaderListener(rootContext));
// Create the dispatcher servlet's Spring application context
XmlWebApplicationContext servletContext =
new XmlWebApplicationContext();
servletContext.setConfigLocation("/WEB-INF/spring/appServlet/servlet-context.xml");
// add the dispatcher servlet and map it to /
ServletRegistration.Dynamic dispatcher =
context.addServlet("springDispatcher", new DispatcherServlet(servletContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
which loads the spring configuration files(root-context.xml, servlet-context.xml) from the locations you've used in your project.
The fixed version which uses the WebApplicationInitializer can be found on github. I've sent you a pull request.
The console output of the fixed version is:
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#76dc331c: defining beans [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.web.servlet.view.InternalResourceViewResolver#0,homeController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#5c23f9fd
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.dom.son.HomeController.home(java.util.Locale,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'springDispatcher': initialization completed in 430 ms
Jun 21, 2015 12:45:28 PM org.apache.coyote.AbstractProtocol start
Information: Starting ProtocolHandler ["http-bio-8080"]
Jun 21, 2015 12:45:28 PM org.apache.coyote.AbstractProtocol start
Information: Starting ProtocolHandler ["ajp-bio-8009"]
Jun 21, 2015 12:45:28 PM org.apache.catalina.startup.Catalina start
Information: Server startup in 2048 ms
INFO : com.dom.son.HomeController - Welcome home! The client locale is de_DE.
In order to fix your eclipse problem I would suggest to delete the old project from eclipse and re-import the fixed version from github.
In Eclipse:
In the Servers view stop your Tomcat instances.
Remove the deployments from your Tomcat (context menu - > delete)
Delete the Project (ideally remove it from disk, or move it to a different location)
Check out the fixed version (mine or yours with my changes)
Re-import the fixed version (File -> Import.... -> Maven -> Existing
Maven Project)

Error 404 after deploying a simple Spring MVC app (without web.xml)

I want to learn some basics of Spring MVC based fully on annotations. I started with this tutorial.
After cloning the repository
hg clone https://bitbucket.org/arnelism/snoutbook
and building the war file
mvn package
I am deploying the app by simply copying the war file to the webapps directory of my Apache Tomcat 7.0.12 instance. I am stopping and starting the server.
INFORMATION: Starting Servlet Engine: Apache Tomcat/7.0.12
Sep 12, 2014 3:37:18 PM org.apache.catalina.startup.HostConfig deployWAR
INFORMATION: Deploying web application archive Snoutbook-1.0.0-SNAPSHOT.war
Sep 12, 2014 3:37:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMATION: Deploying web application directory docs
Sep 12, 2014 3:37:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMATION: Deploying web application directory examples
Sep 12, 2014 3:37:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMATION: Deploying web application directory host-manager
Sep 12, 2014 3:37:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMATION: Deploying web application directory manager
Sep 12, 2014 3:37:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMATION: Deploying web application directory ROOT
Sep 12, 2014 3:37:27 PM org.apache.coyote.AbstractProtocolHandler start
INFORMATION: Starting ProtocolHandler ["http-bio-8080"]
Sep 12, 2014 3:37:27 PM org.apache.coyote.AbstractProtocolHandler start
INFORMATION: Starting ProtocolHandler ["ajp-bio-8009"]
Sep 12, 2014 3:37:27 PM org.apache.catalina.startup.Catalina start
INFORMATION: Server startup in 8826 ms
Unfortunately after this operation I am receiving the error 404 by displaying the page.
http://localhost:8080/Snoutbook-1.0.0-SNAPSHOT/
I have been looking for a solution for over 2 hours and have not been able to find the cause. Did somebody have a similar issue?
EDIT
I tried with the newest Tomcat version apache-tomcat-8.0.12. The problem persists. There is however more info printed in the console while deploying the web app.
12-Sep-2014 17:13:20.038 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployWAR Deploying web application archive D:\Users\b21090094\apac
he-tomcat-8.0.12\webapps\Snoutbook-1.0.0-SNAPSHOT.war
12-Sep-2014 17:13:23.132 INFO [localhost-startStop-1] org.apache.catalina.util.S
essionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for s
ession ID generation using [SHA1PRNG] took [255] milliseconds.
12-Sep-2014 17:13:23.169 INFO [localhost-startStop-1] org.springframework.web.se
rvlet.FrameworkServlet.initServletBean FrameworkServlet 'dispatcher': initializa
tion started
12-Sep-2014 17:13:23.182 INFO [localhost-startStop-1] org.springframework.contex
t.support.AbstractApplicationContext.prepareRefresh Refreshing WebApplicationCon
text for namespace 'dispatcher-servlet': startup date [Fri Sep 12 17:13:23 CEST
2014]; root of context hierarchy
12-Sep-2014 17:13:23.278 INFO [localhost-startStop-1] org.springframework.contex
t.annotation.ClassPathScanningCandidateComponentProvider.registerDefaultFilters
JSR-250 'javax.annotation.ManagedBean' found and supported for component scannin
g
12-Sep-2014 17:13:23.281 INFO [localhost-startStop-1] org.springframework.web.co
ntext.support.AnnotationConfigWebApplicationContext.loadBeanDefinitions Register
ing annotated classes: [class com.zeroturnaround.snoutbook.init.WebappConfigJpa]
12-Sep-2014 17:13:23.429 INFO [localhost-startStop-1] org.springframework.contex
t.annotation.ClassPathScanningCandidateComponentProvider.registerDefaultFilters
JSR-250 'javax.annotation.ManagedBean' found and supported for component scannin
g
12-Sep-2014 17:13:23.921 INFO [localhost-startStop-1] org.springframework.beans.
factory.support.DefaultListableBeanFactory.preInstantiateSingletons Pre-instanti
ating singletons in org.springframework.beans.factory.support.DefaultListableBea
nFactory#7169a1: defining beans [org.springframework.context.annotation.internal
ConfigurationAnnotationProcessor,org.springframework.context.annotation.internal
AutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequ
iredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnn
otationProcessor,org.springframework.context.annotation.internalPersistenceAnnot
ationProcessor,webappConfigJpa,org.springframework.context.annotation.Configurat
ionClassPostProcessor$ImportAwareBeanPostProcessor#0,addPetForm,snoutContoller,s
noutDao,org.springframework.aop.config.internalAutoProxyCreator,delegatingWebMvc
Configuration,requestMappingHandlerMapping,viewControllerHandlerMapping,beanName
HandlerMapping,resourceHandlerMapping,defaultServletHandlerMapping,requestMappin
gHandlerAdapter,mvcConversionService,mvcValidator,httpRequestHandlerAdapter,simp
leControllerHandlerAdapter,handlerExceptionResolver,proxyTransactionManagementCo
nfiguration,org.springframework.transaction.config.internalTransactionAdvisor,tr
ansactionAttributeSource,transactionInterceptor,transactionManager,entityManager
Factory,setupViewResolver,getDataSource]; root of factory hierarchy
12-Sep-2014 17:13:24.225 INFO [localhost-startStop-1] org.springframework.orm.jp
a.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory Buildi
ng JPA container EntityManagerFactory for persistence unit 'default'
12-Sep-2014 17:13:24.657 INFO [localhost-startStop-1] org.hibernate.annotations.
common.Version. HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
12-Sep-2014 17:13:24.676 INFO [localhost-startStop-1] org.hibernate.Version.logV
ersion HHH000412: Hibernate Core {4.1.2}
12-Sep-2014 17:13:24.681 INFO [localhost-startStop-1] org.hibernate.cfg.Environm
ent. HHH000206: hibernate.properties not found
12-Sep-2014 17:13:24.686 INFO [localhost-startStop-1] org.hibernate.cfg.Environm
ent.buildBytecodeProvider HHH000021: Bytecode provider name : javassist
12-Sep-2014 17:13:24.772 INFO [localhost-startStop-1] org.hibernate.ejb.Ejb3Conf
iguration.configure HHH000204: Processing PersistenceUnitInfo [
name: default
...]
12-Sep-2014 17:13:25.524 INFO [localhost-startStop-1] org.hibernate.service.jdbc
.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionP
rovider HHH000130: Instantiating explicit connection provider: org.hibernate.ejb
.connection.InjectedDataSourceConnectionProvider
12-Sep-2014 17:13:26.275 INFO [localhost-startStop-1] org.hibernate.dialect.Dial
ect. HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
12-Sep-2014 17:13:26.356 INFO [localhost-startStop-1] org.hibernate.engine.trans
action.internal.TransactionFactoryInitiator.initiateService HHH000268: Transacti
on strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFacto
ry
12-Sep-2014 17:13:26.374 INFO [localhost-startStop-1] org.hibernate.hql.internal
.ast.ASTQueryTranslatorFactory. HHH000397: Using ASTQueryTranslatorFactory
12-Sep-2014 17:13:26.498 INFO [localhost-startStop-1] . HV0000
01: Hibernate Validator 4.3.0.Final
12-Sep-2014 17:13:27.699 INFO [localhost-startStop-1] org.springframework.web.se
rvlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod Mapped "{[/addP
et],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto
public java.lang.String com.zeroturnaround.snoutbook.controllers.AddPetForm.setu
pForm(org.springframework.ui.Model)
12-Sep-2014 17:13:27.700 INFO [localhost-startStop-1] org.springframework.web.se
rvlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod Mapped "{[/addP
et],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto
public java.lang.String com.zeroturnaround.snoutbook.controllers.AddPetForm.han
dleSubmit(com.zeroturnaround.snoutbook.form.PetForm,org.springframework.validati
on.BindingResult,org.springframework.web.bind.support.SessionStatus)
12-Sep-2014 17:13:27.701 INFO [localhost-startStop-1] org.springframework.web.se
rvlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod Mapped "{[/pet/
{petId}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" ont
o public java.lang.String com.zeroturnaround.snoutbook.controllers.SnoutContolle
r.pet(java.lang.Long,org.springframework.ui.Model)
12-Sep-2014 17:13:27.702 INFO [localhost-startStop-1] org.springframework.web.se
rvlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod Mapped "{[/owne
rs],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto pub
lic java.lang.String com.zeroturnaround.snoutbook.controllers.SnoutContoller.lis
tOwners(org.springframework.ui.Model)
12-Sep-2014 17:13:27.762 INFO [localhost-startStop-1] org.springframework.web.se
rvlet.handler.AbstractUrlHandlerMapping.registerHandler Mapped URL path [/**] on
to handler of type [class org.springframework.web.servlet.resource.DefaultServle
tHttpRequestHandler]
12-Sep-2014 17:13:28.129 INFO [localhost-startStop-1] org.springframework.web.se
rvlet.FrameworkServlet.initServletBean FrameworkServlet 'dispatcher': initializa
tion completed in 4960 ms
12-Sep-2014 17:13:28.140 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployWAR Deployment of web application archive D:\Users\b21090094\
apache-tomcat-8.0.12\webapps\Snoutbook-1.0.0-SNAPSHOT.war has finished in 8,103
ms
12-Sep-2014 17:13:28.141 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deploying web application directory D:\Users\b21090
094\apache-tomcat-8.0.12\webapps\docs
12-Sep-2014 17:13:28.167 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deployment of web application directory D:\Users\b2
1090094\apache-tomcat-8.0.12\webapps\docs has finished in 26 ms
12-Sep-2014 17:13:28.168 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deploying web application directory D:\Users\b21090
094\apache-tomcat-8.0.12\webapps\examples
12-Sep-2014 17:13:28.537 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deployment of web application directory D:\Users\b2
1090094\apache-tomcat-8.0.12\webapps\examples has finished in 370 ms
12-Sep-2014 17:13:28.538 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deploying web application directory D:\Users\b21090
094\apache-tomcat-8.0.12\webapps\host-manager
12-Sep-2014 17:13:28.572 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deployment of web application directory D:\Users\b2
1090094\apache-tomcat-8.0.12\webapps\host-manager has finished in 34 ms
12-Sep-2014 17:13:28.573 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deploying web application directory D:\Users\b21090
094\apache-tomcat-8.0.12\webapps\manager
12-Sep-2014 17:13:28.633 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deployment of web application directory D:\Users\b2
1090094\apache-tomcat-8.0.12\webapps\manager has finished in 61 ms
12-Sep-2014 17:13:28.633 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deploying web application directory D:\Users\b21090
094\apache-tomcat-8.0.12\webapps\ROOT
12-Sep-2014 17:13:28.659 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deployment of web application directory D:\Users\b2
1090094\apache-tomcat-8.0.12\webapps\ROOT has finished in 26 ms
12-Sep-2014 17:13:28.663 INFO [main] org.apache.coyote.AbstractProtocol.start St
arting ProtocolHandler ["http-nio-8080"]
12-Sep-2014 17:13:28.676 INFO [main] org.apache.coyote.AbstractProtocol.start St
arting ProtocolHandler ["ajp-nio-8009"]
12-Sep-2014 17:13:28.682 INFO [main] org.apache.catalina.startup.Catalina.start
Server startup in 8701 ms
After that I am still getting Error 404.
Try to use http://localhost:8080/Snoutbook-1.0.0-SNAPSHOT/owners
When you upload war file to webapp folder of tomcat, by default tomcat let you access the webapp with the war's name. And then when you look at the web app initializer (the subtitute of web.xml), it's registering the DispatcherServlet with / mapping. Next, you look at the controller, it have #RequestMapping pointed to /owners.
Hence, the path is:
host:port + war-name + servlet-mapping + controller-mapping
equals to
localhost:8080/ + Snoutbook-1.0.0-SNAPSHOT/ + / + owners
equals to
http://localhost:8080/Snoutbook-1.0.0-SNAPSHOT/owners

Hibernate and Spring MVC. Transaction not working

I get following error when I try use my DAO. I don know where is problem. I please for help.
Error look like this:
Request processing failed; nested exception is org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
This is my POJO class:
#Entity
#Table(name = "contacts")
public class Customer {
#Id
#Column(name="ID")
#GeneratedValue
private Integer id;
#Column(name="firstname")
private String name;
#Column(name="lastname")
private String surname;
#Column(name = "telephone")
private String telephoneNumber;
#Column(name = "email")
private String email;
DAO class:
#Repository
public class CustomerResource implements DAO_INTERFACE {
#Autowired
private SessionFactory sf;
#Override
public void addCustomer() {
}
#Override
public List<Customer> getList() {
return sf.getCurrentSession().createQuery("from Customer").list();
}
#Override
public void delete(int id) {
}
}
Service:
#Service
public class CustomerService implements CustomerDatabaseInterface {
#Autowired
private DAO_INTERFACE customerRepo;
#Transactional
public List<Customer> getCustomers() {
return customerRepo.getList();
}
}
servlet-context.xml:
<resources mapping="/resources/**" location="/resources/" />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="pl.project" />
</beans:beans>
root-context.xml:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/spring/database.properties"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:url="${db.url}"
p:driverClassName="${db.driverClassName}"
p:username="${db.username}"
p:password="${db.password}"/>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>pl.project.model.Customer</value>
</list>
</property>
</bean>
<tx:annotation-driven/>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
Error log :
cze 09, 2014 7:31:39 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_05\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\MySQL\MySQL Utilities 1.3.6\;.
cze 09, 2014 7:31:39 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Test Project' did not find a matching property.
cze 09, 2014 7:31:39 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
cze 09, 2014 7:31:39 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
cze 09, 2014 7:31:39 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 449 ms
cze 09, 2014 7:31:39 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
cze 09, 2014 7:31:39 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
cze 09, 2014 7:31:40 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
cze 09, 2014 7:31:40 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Mon Jun 09 19:31:41 CEST 2014]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/root-context.xml]
INFO : org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - Loading properties file from ServletContext resource [/WEB-INF/spring/database.properties]
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#69e74d06: defining beans [propertyConfigurer,dataSource,sessionFactory,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,transactionManager]; root of factory hierarchy
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 1054 ms
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization started
cze 09, 2014 7:31:42 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'appServlet'
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'appServlet-servlet': startup date [Mon Jun 09 19:31:42 CEST 2014]; parent: Root WebApplicationContext
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#415ccca5: defining beans [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.web.servlet.view.InternalResourceViewResolver#0,homeController,customerResource,customerService,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#69e74d06
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String pl.project.controller.HomeController.home(org.springframework.ui.Model)
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization completed in 457 ms
cze 09, 2014 7:31:42 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
cze 09, 2014 7:31:42 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
cze 09, 2014 7:31:42 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3143 ms
cze 09, 2014 7:32:03 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/controller] threw exception [Request processing failed; nested exception is org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here] with root cause
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544)
at pl.project.model.CustomerResource.getList(CustomerResource.java:26)
at pl.project.model.CustomerService.getCustomers(CustomerService.java:18)
at pl.project.controller.HomeController.home(HomeController.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I am beginning programmer. I just learn hibernate and Spring.
You don't seem to have transaction management correctly configured for your spring application because you are scanning for everything in your dispatcher servlet.
<context:component-scan base-package="pl.project" />
You might have duplicated beans in the component-scanning. Both component-scan elements i.e in the dispatcher-servlet-context and the root-context detect the same elements hence instantiating your DAO service twice.
Fix your component-scan elements by scanning only your controller classes in the dispatcher-servlet-context and excluding your controller classes from the component scan in the root-context, something like this
Dispatcher Servlet Context:
<context:component-scan base-package="pl.project.controller" />
Root application context (Datasource context)
<context:component-scan base-package="pl.project">
<context:exclude-filter type="regex" expression="pl.project.controller.*"/>
</context:component-scan>
Hi you should keep in servlet-context.xml things related to MVC like views and controllers, and move the services, repositories to the root-context(application-context).

Why embedded OpenEJB fails to deploy my application?

I can't understand why an embedded OpenEJB container fails at the beginning with very un-informative message (sorry for a long log):
Running com.XXX.MyTest
Apache OpenEJB 3.1.3 build: 20101015-05:42
http://openejb.apache.org/
INFO - openejb.home = [skipped...]
INFO - openejb.base = [skipped...]
INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Found PersistenceModule in classpath: [skipped...]/target/classes
INFO - Found EjbModule in classpath: [skipped...]/target/test-classes
INFO - Beginning load: [skipped...]/target/classes
INFO - AltDD persistence.xml -> file:[skipped...]/target/classes/META-INF/test.persistence.xml
INFO - AltDD persistence.xml -> file:[skipped...]/target/classes/META-INF/test.persistence.xml
INFO - Beginning load: [skipped...]/target/test-classes
INFO - Configuring enterprise application: classpath.ear
INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
INFO - Auto-creating a container for bean Finder: Container(type=STATELESS, id=Default Stateless Container)
INFO - Configuring PersistenceUnit(name=wid, provider=org.hibernate.ejb.HibernatePersistence)
INFO - Configuring Service(id=Default JDBC Database, type=Resource, provider-id=Default JDBC Database)
INFO - Auto-creating a Resource with id 'Default JDBC Database' of type 'DataSource for 'abc'.
INFO - Configuring Service(id=Default Unmanaged JDBC Database, type=Resource, provider-id=Default Unmanaged JDBC Database)
INFO - Auto-creating a Resource with id 'Default Unmanaged JDBC Database' of type 'DataSource for 'abc'.
INFO - Adjusting PersistenceUnit abc <jta-data-source> to Resource ID 'Default JDBC Database' from 'null'
INFO - Adjusting PersistenceUnit abc <non-jta-data-source> to Resource ID 'Default Unmanaged JDBC Database' from 'null'
INFO - Enterprise application "classpath.ear" loaded.
INFO - Assembling app: classpath.ear
Oct 28, 2010 2:00:20 PM org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.5.6-Final
Oct 28, 2010 2:00:20 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.5.6-Final
Oct 28, 2010 2:00:20 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Oct 28, 2010 2:00:20 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : javassist
Oct 28, 2010 2:00:20 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Oct 28, 2010 2:00:20 PM org.hibernate.annotations.common.Version <clinit>
INFO: Hibernate Commons Annotations 3.2.0.Final
Oct 28, 2010 2:00:20 PM org.hibernate.ejb.Version <clinit>
INFO: Hibernate EntityManager 3.5.6-Final
Oct 28, 2010 2:00:20 PM org.hibernate.ejb.Ejb3Configuration configure
INFO: Processing PersistenceUnitInfo [
name: abc
...]
INFO - PersistenceUnit(name=abc, provider=org.hibernate.ejb.HibernatePersistence) - provider time 328ms
INFO - Undeploying app: classpath.ear
ERROR - Application could not be deployed: classpath.ear
org.apache.openejb.OpenEJBException: Creating application failed: classpath.ear: org.apache.openejb.persistence.PersistenceUnitInfoImpl.getValidationMode()Ljavax/persistence/ValidationMode;
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:679)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:450)
at org.apache.openejb.assembler.classic.Assembler.buildContainerSystem(Assembler.java:368)
at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:280)
at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:125)
at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:60)
at org.apache.openejb.OpenEJB.init(OpenEJB.java:271)
at org.apache.openejb.OpenEJB.init(OpenEJB.java:250)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[skipped...]
Could you please help? Thanks.
That's because you're using JPA 2.0 which is AFAIK not yet supported by OpenEJB, see this thread and OPENEJB-1236. If you look closely at the Jira issue, it looks like this is fixed in the trunk. I just don't if the subtask is blocking or if it would work with a SNAPSHOT version of the trunk.

Categories

Resources