Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Tuesday, November 01, 2022

Spring Boot: Unable to start embedded Tomcat while using maven

Untitled

2022-06-21 10:40:14.696  WARN 10965 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2022-06-21 10:40:14.708  INFO 10965 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-06-21 10:40:14.796 ERROR 10965 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:165) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) ~[spring-context-5.3.20.jar:5.3.20]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) [spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) [spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) [spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) [spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) [spring-boot-2.7.0.jar:2.7.0]
    at com.javatechie.report.SpringBootJasperReportApplication.main(SpringBootJasperReportApplication.java:38) [classes/:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.(TomcatWebServer.java:104) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:479) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:211) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:184) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.7.0.jar:2.7.0]
    ... 8 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'formContentFilter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter]: Factory method 'formContentFilter' threw exception; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.datatype.jsr310.JavaTimeModule]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/datatype/jsr310/ser/ZoneIdSerializer
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:212) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:175) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:170) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAdaptableBeans(ServletContextInitializerBeans.java:155) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.ServletContextInitializerBeans.(ServletContextInitializerBeans.java:87) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:262) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:236) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5219) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_191]
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_191]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_191]
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_191]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123) ~[spring-boot-2.7.0.jar:2.7.0]
    ... 13 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter]: Factory method 'formContentFilter' threw exception; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.datatype.jsr310.JavaTimeModule]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/datatype/jsr310/ser/ZoneIdSerializer
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.20.jar:5.3.20]
    ... 54 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.datatype.jsr310.JavaTimeModule]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/datatype/jsr310/ser/ZoneIdSerializer
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:224) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:146) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.registerWellKnownModulesIfAvailable(Jackson2ObjectMapperBuilder.java:832) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.configure(Jackson2ObjectMapperBuilder.java:691) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:674) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.(MappingJackson2HttpMessageConverter.java:59) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.(AllEncompassingFormHttpMessageConverter.java:91) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.web.filter.FormContentFilter.(FormContentFilter.java:61) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.boot.web.servlet.filter.OrderedFormContentFilter.(OrderedFormContentFilter.java:29) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.formContentFilter(WebMvcAutoConfiguration.java:177) ~[spring-boot-autoconfigure-2.7.0.jar:2.7.0]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.20.jar:5.3.20]
    ... 55 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/datatype/jsr310/ser/ZoneIdSerializer
    at com.fasterxml.jackson.datatype.jsr310.JavaTimeModule.(JavaTimeModule.java:158) ~[jackson-datatype-jsr310-2.13.3.jar:2.13.3]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_191]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_191]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_191]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_191]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211) ~[spring-beans-5.3.20.jar:5.3.20]
    ... 69 common frames omitted

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  03:42 min
[INFO] Finished at: 2022-06-21T10:40:14+06:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.7.0:run (default-cli) on project spring-boot-jasper-report: Application finished with exit code: 1 -> [Help 1]

This may happen while running:

if accidentally spring-boot-starter-parent dependency is missing from pom.xml:

Make sure Spring Boot Starter Parent dependency is included at the top of pom.xml. Not inside dependencies tag but, before build tag. Like:

which includes spring-boot-starter-tomcat dependency. Also make sure another process not using default tomcat port. If so, change server.port property inside application.properties.

Tuesday, August 09, 2016

Spring Boot : Generate new maven project via Spring Boot

Spring Boot awsome CLI tool lets get start with new template project real quick :)

Go to http://start.spring.io/

Set group and package names,packaging(standalone(jar) or web(war)),project type(maven orgradle).
You can also select java version,language(java or groovy) and pre-add lots of dependencies(jpa,template engin,AOP and lote more :) ).

Click Generate project button and  project will be downloaded as zip :)

Doing it in shell/command prompt:
so that we can get it done via script:
  1. #generate & download
  2. spring init --build=maven --java-version=1.8 --dependencies=mail --packaging=jar skeleton.zip
  3. #unzip
  4. unzip skeleton.zip
  5. #remove zip
  6. rm -f skeleton.zip
  7. #we have our project in current directory :)
  8. cat pom.xml
look at the generated pom.xml:-
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4.     <modelVersion>4.0.0</modelVersion>
  5.     <groupId>com.example</groupId>
  6.     <artifactId>skeleton</artifactId>
  7.     <version>0.0.1-SNAPSHOT</version>
  8.     <packaging>jar</packaging>
  9.     <name>demo</name>
  10.     <description>Demo project for Spring Boot</description>
  11.     <parent>
  12.         <groupId>org.springframework.boot</groupId>
  13.         <artifactId>spring-boot-starter-parent</artifactId>
  14.         <version>1.4.0.RELEASE</version>
  15.         <relativePath/> <!-- lookup parent from repository -->
  16.     </parent>
  17.     <properties>
  18.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  19.         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  20.         <java.version>1.8</java.version>
  21.     </properties>
  22.     <dependencies>
  23.         <dependency>
  24.             <groupId>org.springframework.boot</groupId>
  25.             <artifactId>spring-boot-starter-mail</artifactId>
  26.         </dependency>
  27.         <dependency>
  28.             <groupId>org.springframework.boot</groupId>
  29.             <artifactId>spring-boot-starter-test</artifactId>
  30.             <scope>test</scope>
  31.         </dependency>
  32.     </dependencies>
  33.     <build>
  34.         <plugins>
  35.             <plugin>
  36.                 <groupId>org.springframework.boot</groupId>
  37.                 <artifactId>spring-boot-maven-plugin</artifactId>
  38.             </plugin>
  39.         </plugins>
  40.     </build>
  41. </project>
more examples here:-
http://docs.spring.io/spring-boot/docs/current/reference/html/cli-using-the-cli.html#cli-init

Tuesday, June 23, 2015

java exception : Expected org.codehaus.plexus.components.io.resources.PlexusIoArchivedResourceCollection, got org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection

Running maven command with maven assembly plugin
  1. mvn clean compile assembly:single
may some times throw:

Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4:single (default-cli) on project : Failed to create assembly: Error adding file-set for to archive: Expected org.codehaus.plexus.components.io.resources.PlexusIoArchivedResourceCollection, got org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection -> [Help 1]

This may happen if by any chances maven project structure is not standard.For example: if it misses src/main/java

Non-standard structure:
src->com->company->package->files
Standard structure:
src->main->java->com->company->package->files

Solution:

  1. #navigate to project dir where pom.xml exists
  2. cd PROJECT_DIR
  3. cd src
  4. #create directories
  5. mkdir main/
  6. mkdir main/java/
  7. #move source packages & files into src/main/java directory.
  8. mv com/ main/java/

Sunday, June 22, 2014

CentOS : Maven install Script(.sh)

  1. #download maven tar
  2. wget http://mirror.cc.columbia.edu/pub/software/apache/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.tar.gz
  3. #untar
  4. tar xzf apache-maven-3.0.5-bin.tar.gz -C /usr/local/
  5. #delete unnecessary back-up
  6. rm -f apache-maven-3.0.5-bin.tar.gz
  7. #install
  8. cd /usr/local
  9. #create symlink
  10. ln -s apache-maven-3.0.5 maven
  11. #create environment vars
  12. export M2_HOME=/usr/local/maven
  13. export PATH=${M2_HOME}/bin:${PATH}
  14. #check installation
  15. mvn -version
Download CentOS Maven Install Script(.sh) from Here.

Wednesday, May 28, 2014

Running maven web project with maven tomcat7 plugin

With maven tomcat7 plugin you won't have download,install and configure Tomcat server seperately.Maven can do it for you.Just run:
mvn tomcat7:run
with a tomcat7 maven plugin enabled project and browse to localhost:port/path
In your pom.xml simply put this plugin:
  1. <plugin>
  2. <groupId>org.apache.tomcat.maven</groupId>
  3. <artifactId>tomcat7-maven-plugin</artifactId>
  4. <version>2.0</version>
  5. <configuration>
  6. <server>tomcat-development-server</server>
  7. <port>9966</port> <!--make sure port doesnt conflict with others -->
  8. <path>/SpringMVC</path><!--http://localhost:9966/SpringMVC/ -->
  9. </configuration>
  10. </plugin>

Example spring maven hello world web project pom.xml:
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2.      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3.     <modelVersion>4.0.0</modelVersion>
  4.     <groupId>com.mohi</groupId>
  5.     <artifactId>SpringMVC</artifactId>
  6.     <packaging>war</packaging>
  7.     <version>1.0-SNAPSHOT</version>
  8.     <name>SpringMVC Maven Webapp</name>
  9.     <url>http://maven.apache.org</url>
  10.     <dependencies>
  11.         <dependency>
  12.             <groupId>org.springframework</groupId>
  13.             <artifactId>spring-webmvc</artifactId>
  14.             <version>4.0.3.RELEASE</version>
  15.         </dependency>
  16.     </dependencies>
  17.     <build>
  18.         <plugins>
  19.             <plugin>
  20.                 <groupId>org.apache.maven.plugins</groupId>
  21.                 <artifactId>maven-compiler-plugin</artifactId>
  22.                 <version>2.3.2</version>
  23.             </plugin>
  24.             <plugin>
  25.                 <groupId>org.apache.tomcat.maven</groupId>
  26.                 <artifactId>tomcat7-maven-plugin</artifactId>
  27.                 <version>2.0</version>
  28.                 <configuration>
  29.                     <server>tomcat-development-server</server>
  30.                     <port>9966</port>
  31.                     <path>/SpringMVC</path>
  32.                 </configuration>
  33.             </plugin>
  34.         </plugins>
  35.     </build>
  36. </project>

Sample code:
Here is a Spring Helloworld maven with tomcat7 plugin example project SpringHelloworldMavenTomcat7PluginExample.zip
Download ,unzip and run:
mvn clean install tomcat7:run
Browse to localhost:9966/SpringMVC/welcome

Sunday, May 04, 2014

Spring 3 Hibernate 4 Annotations Entity Manager PostgreSQL maven standalone example

Create the sample postgresql database at first in PgAdmin :
  1. CREATE DATABASE "TESTS"
  2. WITH OWNER = postgres
  3. ENCODING = 'UTF8'
  4. TABLESPACE = pg_default
  5. CONNECTION LIMIT = -1;

Then create the table in databse 'TESTS':
  1. CREATE TABLE USERS (
  2. ID serial NOT NULL,
  3. USERNAME text NOT NULL,
  4. NAME text NOT NULL
  5. );

Download the example from github.Build(mvn clean install) And run Main.java