How to start a Maven Spring JSF 2.0 Richfaces project? - spring

For some of you it might sound trvial, but for days I have been fighting with pom.xml files and facets in order to build a Spring JSF 2.0 Maven project (run on tomcat 7.0) with RichFaces, but with no success. Can someone please reference me to a full working example ,I am using STS (tutorial from scratch , I can download a fully working example but I want to learn how to create one ) ?

So after few days of work I came to the conclusion I have to do the dirty work therefore I will explain how I managed to start a project :
download sts
open template project , in my case it was spring integration with hibernate
right click on project-> preferences->facets
change to JSF 2.0 and web dynamic above 2.5(require above 1.5 java )
add to the maven dependencies ( pom.xml ):
<!-- spring hibernate 3 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-hibernate3</artifactId>
<version>2.0.8</version>
</dependency>
set up your
<property name="dataSource" ref="dataSource" />
the ref is pointed to this bean :
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:mem:."/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
or any other you decide ...
add to your project pom :
<dependency>
<groupId>org.richfaces.framework</groupId>
<artifactId>richfaces-impl</artifactId>
<version>3.2.2.GA</version>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-ui</artifactId>
<version>3.2.2.GA</version>
</dependency>
start praying it will work :)

Related

Spring Session JdbcHttpSessionConfiguration causes JPA bean not to start

I am trying to use Spring Session with PostgreSQL for storing http sessions.Followed https://docs.spring.io/spring-session/docs/2.0.4.RELEASE/reference/html5/guides/xml-jdbc.html#httpsession-jdbc-xml-sample
Here is my XML
<context:annotation-config/>
<bean class="org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver"></property>
<property name="url" value="jdbc:postgresql://127.0.0.1:5432/myapp"></property>
<property name="username" value="postgres"></property>
<property name="password" value=""></property>
</bean>
<bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<constructor-arg ref="dataSource"/>
My application is already using Spring JPA for other DB operations. But Problem is after I added
<context:annotation-config/>
<bean class="org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration"/>
my JPA beans are not loaded on the startup and hence application is not getting started.
I tried following steps.
Created two data sources beans. One was already there for JPA and one as shown in the XML with id 'dataSource'. JPA one is also with same bean properties but with different id.
Removed one in XML and renamed JPA one also to 'dataSource' as I read JdbcHttpSessionConfiguration looks for bean 'dataSource' and by assuming both JPA and session JDBC will use the same one
But both the cases result in the same error.
I was not getting any error in catalina.out. So put try catch in my application where it tries to get the JPA bean. I am getting the following error.
Cannot find class [org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration] for bean
with name 'org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration#0'
defined in class path resource [applicationContext_Web.xml]; nested exception is java.lang.ClassNotFoundException:
org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration
Dependency added in pom
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-jdbc</artifactId>
<version>2.0.4.RELEASE</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
I could solve it . Somehow maven was still picking spring-session-core jar instead of spring-session-jdbc. I just removed pom and again did a maven update. Not sure how it took the correct one then.

spring application Could not load JDBC driver class :oracle.jdbc.driver.OracleDriver

I am new to spring and developing spring jdbc application. but driver class is not loaded. am getting exception that
org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]
and my xml file is as follows:
<bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:#localhost:1521:xe" />
<property name="username" value="system" />
property name="password" value="surekha" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="ds"></property>
</bean>
<bean id="edao" class="EmployeeDao">
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean>
</beans>
anyone help me to this problem. thanks in advance.
In your pom.xml , add this dependency :
<dependency>
<groupId>oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
Add Following dependency in pom.xml
<dependency>
<groupId>com.oracle</groupId>
<artifactId>oracle</artifactId>
<version>10.2.0.2.0</version>
</dependency>
I had the Same problem even adding the maven dependency in my pom.xml
I downloaded manualy the .jar in https://mvnrepository.com/artifact/com.oracle/ojdbc6/12.1.0.1-atlassian-hosted
and it worked for my project.
Add this jdbc-oracle.jar file into your project...
jdbc-oracle.jar is available in http://www.java2s.com/Code/Jar/j/Downloadjdbcoraclejar.htm

Spring JDBC Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]

I wonder if any one could help me with this. I encountered an issue when I tried writing code with Spring JDBC. When I ran the server, I got the message like I mentioned in the title. I have google it and someone said that you should import ojdbc.jar. However, I have already imported it. Here comes my code:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#192.168.0.13:1521/orcl" />
<property name="username" value="Hibernate" />
<property name="password" value="123456" />
</bean>
</beans>
Please kindly suggest if I have done something wrong. Many thanks in advance.
Make sure that you have ojdbc.jar gets added into your class path. If you want, you can also double check it by opening .classpath file and look for ojdbc.jar entry. If you don't have it, download it from the the maven repo as mentioned below:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
.......
<repositories>
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
</repositories>
Download the ojdbc jar from here
Put ojdb6.jar in some folder in your project (let's use lib).
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>11.2.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/ojdbc6.jar</systemPath>
</dependency>
Then do :
mvn install:install-file \
-Dfile=path/to/ojdbc6.jar \
-DgroupId=com.oracle \
-DartifactId=ojdbc6 \
-Dversion=11.2.0 \
-Dpackaging=jars
I just put ojdbc6.jar in apache tom cat installation directory in lib directory
D:\TOOLS\apache tomcat server\Tomcat 8.0\lib
It solved my problem.
In my case the problem was setting the scope to runtime:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.0.0.jre8</version>
<scope>runtime</scope>
</dependency>
Just copy ojdbc6.jar into tomcat/lib folder as in a picture below.
example tomcat/lib/
If you are using Maven as your build tool, then add this below dependency. Make sure you have the correct version of ojdbcXX.jar file corresponding to the database version. For me, I have an Oracle 11g database, hence I am using ojdbc6.jar.
Step 1) Add dependency
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>6</version>
<scope>system</scope>
<systemPath>C:\Users\AkhileshPC\Downloads\ojdbc6.jar</systemPath>
</dependency>
Step 2) Install the ojdbcXX.jar in your Maven local repository.
Command > mvn install:install-file "-Dfile =Downloads\ojdbc6.jar" "-DgroupId=com.oracle" "-DartifactId=ojdbc6" "-Dversion=11.2.0.1" "-Dpackaging=jar"
Setting up maven local repository image
Step 3) Make sure your ojdbcXX.jar file is available in the WEB-INF\lib folder of the corresponding project in the .metadata folder.
My case:
C:\Users\AkhileshPC\JavaSpring\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\1007_Spring_Mvc_App_Crud\WEB-INF\lib
web-inf folder path Image
Once all three of these steps are completed, the issue should be resolved.
Try
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:schema_name/123456#192.168.0.13:1521:orcl" />
<property name="username" value="Hibernate" />
<property name="password" value="123456" />
</bean>
</beans>
If you use Spring Boot 2 (I am using Spring Boot 2.0.4.RELEASE, Oracle database 12c), application.properties
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:schema_name/123456#192.168.0.13:1521:xe
spring.datasource.username=Hibernate
spring.datasource.password=123456
(You must have ojdbc7.jar in classpath)
I resolved it in InteliJ like this:
File -> Project Structure -> Libraries -> click on '+' (add new) -> point to the ojdbc.jar path under file system (previously downloaded manually or using some build tool)
I tried to use idea add ojdbc to lib ,but it is not valid.
My final solution is to add ojdbc.jar to tomcat lib dir then restart it.
No fatal error

Spring Tiles Integration Error

I am trying to integrate Tiles 3.0.0 with Spring 3.1, I have all the tile jar files under my lib folder. When I run the web project I get an
java.lang.ClassNotFoundException: org.apache.tiles.startup.BasicTilesInitializer
error. I need some help understanding why I am getting this error. Here is my configuration to setup in my servlet.xml page.
<bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver" />
<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/views/**/views.xml</value>
</list>
</property>
</bean>
Here is a question that's a lot like mine, link, but I've already got my tiles-core-3.0.0 in my build path. So I just need some help understanding how to get over this error.
Morgan
At the time of writing this, Spring still does not support Tiles 3. I'm using Spring 3.1.2 and had to downgrade Tiles back to version 2.2.2 in order for my application to run.
I've make a program working with Spring Framework version 3.2.13.RELEASE and Tiles-3 (version 3.0.5). You need to use following configuration
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles/tiles-definitions.xml</value>
</list>
</property>
</bean>
with dependency
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.5</version>
</dependency>
<!-- Spring Web MVC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.13.RELEASE</version>
</dependency>
I think this is what you're trying to achieve. It works fine in my case !

Class load error on Spring MVC project for Spring newbie

Warning: newbie alert!
I'm in early days of learning Spring and am trying to get my first app up and running which will simply read some data from a DB and display it.
I'm using SpringSource Tool Suite 2.8.0.RELEASE. I've created a new Spring MVC project and want to read some data from a local MySQL DB.
I wrote a simple DAO class:
package com.blah.blah;
import org.springframework.jdbc.core.support.JdbcDaoSuppo rt;
public class MyDAO extends JdbcDaoSupport {
I've added this to the pom.xml file:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
I've added this to the root-context.xml (is this the right config file to update?):
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/dbname" />
<property name="username" value="root" />
<property name="password" value="mypw" />
</bean>
<bean id="jdbcTemplate"
class="org.springframework.jdbc.core.JdbcTemplate" >
<constructor-arg ref="myDataSource"></constructor-arg>
</bean>
<bean id="parentDAO"
class="org.springframework.jdbc.core.support.JdbcD aoSupport">
<property name="dataSource" ref="myDataSource"></property>
</bean>
When I right-click on the project and select Debug As > Debug On Server I get the error:
24-Mar-2012 16:13:42 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of
class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.CannotLoadBeanClassException:
Cannot find class [org.springframework.jdbc.datasource.DriverManagerDataSource]
for bean with name 'myDataSource' defined in ServletContext resource
[/WEB-INF/spring/root-context.xml]; nested exception is
java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource
I've been looking at this for a while and can't figure out what I'm doing wrong. I've found the folder where the app is deployed to (C:\Program Files\springsource\vfabric-tc-server-developer-2.6.1.RELEASE\spring-insight-instance\wtpwebapps\MyAppName\WEB-INF\lib on my machine) and the lib folder contains spring-jdbc-3.1.0.RELEASE.jar and when I open it, I can see the DriverManagerDataSource class file so I don't know why I'm getting the error above.
Any advice greatly appreciated.
Check that the Spring libraries are in the classpath so they are available for the server.
I had the same jar file included in the project twice. Removed one and it worked.
I had the same problem in Eclipse and creating a new workspace solved this problem.
I had added required jar source instead of release. Strange but changing that to release version fixed this problem.

Resources