Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Set up of the java buildpack

  • Loading branch information...
commit 52e65d586b78cac3653788e1a1cf1ba4d7b2c429 1 parent f4ff68c
jeremy-aubert authored
1  Procfile
View
@@ -0,0 +1 @@
+web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --port $PORT target/*.war
22 README.md
View
@@ -1,14 +1,33 @@
Spring Sample
=============
-This is a Java sample using the Spring framework and a MySQL service.
+This is a Java sample using the Spring framework and a MySQL service. This application uses a java
+buildpack.
+
+
+Database configuration
+----------------------
+
+As this example uses a java heroku buildpack, the database configuration requires the environment variable [DATABASE_URL].
+To run the application locally, set the DATABASE_URL variable in your local environment to point to your local mysql database.
+
+For example : export DATABASE_URL=mysql://user:password@localhost/myapp
+
Building the Application
------------------------
+First, set the DATABASE_URL (required for test):
+
+ export DATABASE_URL=mysql://user:password@localhost/myapp
+
To build the application, make sure you have [Maven](http://maven.apache.org/ "Maven") installed.
Then, *cd* into the root directory and execute:
+ mvn clean package
+
+If you do not want to set up a local database, you can skip the test with:
+
mvn clean package -Dmaven.test.skip=true
That will create the *petclinic.war* file in the 'target' directory.
@@ -18,7 +37,6 @@ Deploying the Application
To deploy to stackato:
- mvn clean package -Dmaven.test.skip=true
stackato push -n
You can view the application at the 'Application Deployed URL'.
10 manifest.yml
View
@@ -1,10 +0,0 @@
----
-applications:
- target:
- name: pet-clinic
- mem: 512M
- services:
- mysql-spring:
- type: mysql
- framework:
- name: spring
30 pom.xml
View
@@ -98,12 +98,11 @@
<scope>runtime</scope>
</dependency>
<!-- MySQL JDBC Connector -->
- <!--
- <dependency> <groupId>com.mysql.jdbc</groupId>
+ <dependency> <groupId>com.mysql.jdbc</groupId>
<artifactId>com.springsource.com.mysql.jdbc</artifactId>
- <version>5.1.6</version> </dependency>
- -->
-
+ <version>5.1.6</version>
+ </dependency>
+
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
@@ -291,6 +290,27 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.3</version>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals><goal>copy</goal></goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-runner</artifactId>
+ <version>7.5.4.v20111024</version>
+ <destFileName>jetty-runner.jar</destFileName>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>
6 src/main/resources/jdbc.properties
View
@@ -40,9 +40,9 @@ jpa.showSql=true
# MySQL Settings
jdbc.driverClassName=com.mysql.jdbc.Driver
-jdbc.url=jdbc:h2:mem:
-jdbc.username=sa
-jdbc.password=
+jdbc.url=#{ 'jdbc:mysql://' + @dbUrl.getHost() + @dbUrl.getPath() }
+jdbc.username=#{ @dbUrl.getUserInfo().split(':')[0] }
+jdbc.password=#{ @dbUrl.getUserInfo().split(':')[1] }
# Properties that control the population of schema and data for a new data source
jdbc.initLocation=classpath:db/mysql/initDB.txt
123 src/main/webapp/WEB-INF/petclinic-servlet.xml~
View
@@ -1,123 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- - DispatcherServlet application context for PetClinic's web tier.
--->
-<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" xmlns:context="http://www.springframework.org/schema/context"
- xmlns:oxm="http://www.springframework.org/schema/oxm"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
- http://www.springframework.org/schema/mvc
- http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
-
- <!--
- - The controllers are autodetected POJOs labeled with the @Controller annotation.
- -->
- <context:component-scan base-package="org.springframework.samples.petclinic.web"/>
-
- <!--
- - The form-based controllers within this application provide @RequestMapping
- - annotations at the type level for path mapping URLs and @RequestMapping
- - at the method level for request type mappings (e.g., GET and POST).
- - In contrast, ClinicController - which is not form-based - provides
- - @RequestMapping only at the method level for path mapping URLs.
- -
- - DefaultAnnotationHandlerMapping is driven by these annotations and is
- - enabled by default with Java 5+.
- -->
-
- <!--
- - This bean processes annotated handler methods, applying PetClinic-specific PropertyEditors
- - for request parameter binding. It overrides the default AnnotationMethodHandlerAdapter.
- -->
- <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
- <property name="webBindingInitializer">
- <bean class="org.springframework.samples.petclinic.web.ClinicBindingInitializer"/>
- </property>
- </bean>
-
- <!--
- - This bean resolves specific types of exceptions to corresponding logical
- - view names for error views. The default behaviour of DispatcherServlet
- - is to propagate all exceptions to the servlet container: this will happen
- - here with all other types of exceptions.
- -->
- <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
- <property name="exceptionMappings">
- <props>
- <prop key="org.springframework.web.servlet.PageNotFound">pageNotFound</prop>
- <prop key="org.springframework.dao.DataAccessException">dataAccessFailure</prop>
- <prop key="org.springframework.transaction.TransactionException">dataAccessFailure</prop>
- </props>
- </property>
- </bean>
-
- <!--
- - This view resolver delegates to the InternalResourceViewResolver and BeanNameViewResolver,
- - and uses the requested media type to pick a matching view. When the media type is 'text/html',
- - it will delegate to the InternalResourceViewResolver's JstlView, otherwise to the
- - BeanNameViewResolver. Note the use of the expression language to refer to the contentType
- - property of the vets view bean, setting it to 'application/vnd.springsource.samples.petclinic+xml'.
- -->
- <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
- <property name="mediaTypes">
- <map>
- <entry key="xml" value="#{vets.contentType}"/>
- <entry key="atom" value="#{visits.contentType}"/>
- </map>
- </property>
- <property name="order" value="0"/>
- </bean>
-
- <!--
- - The BeanNameViewResolver is used to pick up the visits view name (below).
- - It has the order property set to 2, which means that this will
- - be the first view resolver to be used after the delegating content
- - negotiating view resolver.
- -->
- <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="1"/>
- <!--
-
- - This bean configures the 'prefix' and 'suffix' properties of
- - InternalResourceViewResolver, which resolves logical view names
- - returned by Controllers. For example, a logical view name of "vets"
- - will be mapped to "/WEB-INF/jsp/vets.jsp".
- -->
- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/"
- p:suffix=".jsp" p:order="2"/>
-
- <!--
- - The AtomView rendering a Atom feed of the visits
- -->
- <bean id="visits" class="org.springframework.samples.petclinic.web.VisitsAtomView"/>
-
- <bean id="vets" class="org.springframework.web.servlet.view.xml.MarshallingView">
- <property name="contentType" value="application/vnd.springsource.samples.petclinic+xml"/>
- <property name="marshaller" ref="marshaller"/>
- </bean>
-
- <oxm:jaxb2-marshaller id="marshaller">
- <oxm:class-to-be-bound name="org.springframework.samples.petclinic.Vets"/>
- </oxm:jaxb2-marshaller>
-
- <!--
- - Message source for this context, loaded from localized "messages_xx" files.
- - Could also reside in the root application context, as it is generic,
- - but is currently just used within PetClinic's web tier.
- -->
- <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"
- p:basename="messages"/>
-
- <!--
- - Static resources
- -->
- <mvc:resources location="/" mapping="/static/**" />
-
- <!--
- - The controllers are autodetected POJOs labeled with the @Controller annotation.
- -->
- <mvc:annotation-driven />
- <context:component-scan base-package="org.springframework.samples.petclinic.web"/>
-
-</beans>
4 src/main/webapp/WEB-INF/spring/applicationContext-dataSource.xml
View
@@ -17,6 +17,10 @@
<!-- (in this case, JDBC-related settings for the dataSource definition below) -->
<context:property-placeholder location="classpath:jdbc.properties"/>
+ <bean class="java.net.URI" id="dbUrl">
+ <constructor-arg value="#{systemEnvironment['DATABASE_URL']}"/>
+ </bean>
+
<!-- DataSource configuration for Apache Commons DBCP. -->
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
<property name="url" value="${jdbc.url}" />
188 src/main/webapp/WEB-INF/web.xml~
View
@@ -1,188 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<web-app 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>Spring PetClinic</display-name>
-
- <description>Spring PetClinic sample application</description>
-
- <!--
- Key of the system property that should specify the root directory of this
- web app. Applied by WebAppRootListener or Log4jConfigListener.
- -->
- <context-param>
- <param-name>webAppRootKey</param-name>
- <param-value>petclinic.root</param-value>
- </context-param>
-
-
-
- <!--
- Location of the Log4J config file, for initialization and refresh checks.
- Applied by Log4jConfigListener.
- -->
- <context-param>
- <param-name>log4jConfigLocation</param-name>
- <param-value>/WEB-INF/classes/log4j.properties</param-value>
- </context-param>
-
- <!--
- - Location of the XML file that defines the root application context.
- - Applied by ContextLoaderServlet.
- -
- - Can be set to:
- - "/WEB-INF/applicationContext-hibernate.xml" for the Hibernate implementation,
- - "/WEB-INF/applicationContext-jpa.xml" for the JPA one, or
- - "/WEB-INF/applicationContext-jdbc.xml" for the JDBC one.
- -->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/spring/applicationContext-jdbc.xml</param-value>
- <!--
- <param-value>/WEB-INF/spring/applicationContext-hibernate.xml</param-value>
- <param-value>/WEB-INF/spring/applicationContext-jpa.xml</param-value>
- -->
-
- <!--
- To use the JPA variant above, you will need to enable Spring load-time
- weaving in your server environment. Out of the box, Spring will try to
- detect the running environment and use the appropriate weaver but if that
- fails, one must enable one by hand or use the VM-wide weaver.
- See PetClinic's readme and/or Spring's JPA documentation for more information.
- -->
- </context-param>
-
- <!--
- - Configures Log4J for this web app.
- - As this context specifies a context-param "log4jConfigLocation", its file path
- - is used to load the Log4J configuration, including periodic refresh checks.
- -
- - Would fall back to default Log4J initialization (non-refreshing) if no special
- - context-params are given.
- -
- - Exports a "web app root key", i.e. a system property that specifies the root
- - directory of this web app, for usage in log file paths.
- - This web app specifies "petclinic.root" (see log4j.properties file).
- -->
- <!-- Leave the listener commented-out if using JBoss -->
- <!--
- <listener>
- <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
- </listener>
- -->
-
- <!--
- - Loads the root application context of this web app at startup,
- - by default from "/WEB-INF/applicationContext.xml".
- - Note that you need to fall back to Spring's ContextLoaderServlet for
- - J2EE servers that do not follow the Servlet 2.4 initialization order.
- -
- - Use WebApplicationContextUtils.getWebApplicationContext(servletContext)
- - to access it anywhere in the web application, outside of the framework.
- -
- - The root context is the parent of all servlet-specific contexts.
- - This means that its beans are automatically available in these child contexts,
- - both for getBean(name) calls and (external) bean references.
- -->
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
-
- <!--
- Defines the 'default' servlet (usually for service static resources).
- Uncomment this in containers (GlassFish) that do not declare this
- implicit definition out of the box, or change the name of the servlet mapping
- below to the appropriate one.
-
- <servlet>
- <servlet-name>default</servlet-name>
- <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
- <init-param>
- <param-name>debug</param-name>
- <param-value>0</param-value>
- </init-param>
- <init-param>
- <param-name>listings</param-name>
- <param-value>false</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- -->
- <!--
- - Map static resources to the default servlet
- - examples:
- - http://localhost:8080/static/images/pets.png
- - http://localhost:8080/static/styles/petclinic.css
- -->
- <servlet-mapping>
- <servlet-name>default</servlet-name>
- <url-pattern>/static/*</url-pattern>
- </servlet-mapping>
-
- <!--
- - Servlet that dispatches request to registered handlers (Controller implementations).
- - Has its own application context, by default defined in "{servlet-name}-servlet.xml",
- - i.e. "petclinic-servlet.xml".
- -
- - A web app can contain any number of such servlets.
- - Note that this web app has a shared root application context, serving as parent
- - of all DispatcherServlet contexts.
- -->
- <servlet>
- <servlet-name>petclinic</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <load-on-startup>2</load-on-startup>
- </servlet>
-
- <!--
- - Maps the petclinic dispatcher to "*.do". All handler mappings in
- - petclinic-servlet.xml will by default be applied to this subpath.
- - If a mapping isn't a /* subpath, the handler mappings are considered
- - relative to the web app root.
- -
- - NOTE: A single dispatcher can be mapped to multiple paths, like any servlet.
- -->
- <servlet-mapping>
- <servlet-name>petclinic</servlet-name>
- <url-pattern>/</url-pattern>
- </servlet-mapping>
-
- <filter>
- <filter-name>httpMethodFilter</filter-name>
- <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
- </filter>
-
- <filter-mapping>
- <filter-name>httpMethodFilter</filter-name>
- <servlet-name>petclinic</servlet-name>
- </filter-mapping>
-
- <session-config>
- <session-timeout>10</session-timeout>
- </session-config>
-
- <error-page>
- <exception-type>java.lang.Exception</exception-type>
- <!-- Displays a stack trace -->
- <location>/WEB-INF/jsp/uncaughtException.jsp</location>
- </error-page>
-
- <!-- eliminate welcome files -->
- <!-- useful for Servlet 3 container (Tomcat 7 and Jetty 6) -->
- <welcome-file-list>
- <welcome-file></welcome-file>
- </welcome-file-list>
-
- <!--
- - Reference to PetClinic database.
- - Only needed if not using a local DataSource but a JNDI one instead.
- -->
- <!--
- <resource-ref>
- <res-ref-name>jdbc/petclinic</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
- -->
-
-</web-app>
9 stackato.yml
View
@@ -0,0 +1,9 @@
+name: pet-clinic
+mem: 256M
+framework:
+ type: buildpack
+env:
+ BUILDPACK_URL: https://github.com/heroku/heroku-buildpack-java.git
+services:
+ mysql-spring:
+ type: mysql
Please sign in to comment.
Something went wrong with that request. Please try again.