Process cxf request with amq - soap

I want to make such a solution:
cxf https soap service gets a request and sends it to activemq queue
1
service implementation gets message from queue 1, process it and
puts to queue 2
endpoint gets response from queue 2 and sends
response to a client
Now, I came with a kind of a solution but I'm not sure how to process response from activemq and send back as SOAP response. My camel blueprints below. Endpoint blueprint:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:soap="http://cxf.apache.org/blueprint/bindings/soap"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://cxf.apache.org/blueprint/bindings/soap http://cxf.apache.org/schemas/configuration/blueprint/soap.xsd">
<bean id="cardServiceEndpoint" class="com.endpoint.card.CardEndpoint">
<argument>
<reference interface="com.card.CardService" />
</argument>
</bean>
<cxf:cxfEndpoint
id="cardEndpoint"
address="https://host:port/soa/card"
serviceClass="com.card.CardService">
<cxf:properties>
<entry key="schema-validation-enabled" value="true" />
</cxf:properties>
</cxf:cxfEndpoint>
<bean id="jaxB" class="org.apache.camel.model.dataformat.JaxbDataFormat">
<property name="prettyPrint" value="true" />
<property name="contextPath" value="com.type.card" />
</bean>
<camelContext id="endpoint-card-cxf" xmlns="http://camel.apache.org/schema/blueprint">
<route id="endpoint-soap-in">
<from uri="cxf:bean:cardEndpoint"/>
<transform>
<simple>${body[0]}</simple>
</transform>
<marshal ref="jaxB"/>
<setHeader headerName="JMSType">
<simple>${headers.operationName}</simple>
</setHeader>
<to uri="amq:q.in"/>
</route>
<route id="endpoint-soap-out">
<from uri="amq:q.out" />
<unmarshal ref="jaxB" />
<!-- STUCK HERE :( -->
</route>
</camelContext>
</blueprint>
Service processor blueprint:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<bean id="cardService" class="com.card.impl.DefaultCardService">
<argument>
<reference interface="com.base.StashService"/>
</argument>
</bean>
<service interface="com.card.CardService" ref="cardService" />
<bean id="amqCardServiceEndpoint" class="com.card.endpoint.AmqCardEndpoint">
<argument ref="cardService" />
</bean>
<bean id="jaxB" class="org.apache.camel.model.dataformat.JaxbDataFormat">
<property name="prettyPrint" value="true" />
<property name="contextPath" value="com.type.base:com.type.card" />
</bean>
<camelContext id="service-card-cx" xmlns="http://camel.apache.org/schema/blueprint">
<route id="card-rq-broker">
<from uri="amq:queue:q.in?asyncConsumer=true" />
<unmarshal ref="jaxB" />
<doTry>
<bean ref="amqCardServiceEndpoint" method="invoke" />
<doCatch>
<exception>com.type.base.BaseException</exception>
<setBody>
<simple>${exception.getFaultInfo()}</simple>
</setBody>
</doCatch>
</doTry>
<marshal ref="jaxB" />
<to uri="amq:q.out" />
</route>
</camelContext>
</blueprint>
Any help or advice?

Use jmsReplyTo to specify the name of the reply queue (if you want a fixed queue name) that Camel should use for listening for the response. See more about request/reply on the Camel JMS documentation.
<to uri="amq:q.in?jmsReplyTo=q.out"/>
// continue here when reply is back
http://camel.apache.org/jms

Related

Redirect after logout to the wrong language

I am using spring security and i18n.
My application has 2 languages: Fr and En, Fr being the default one. However, when I logged in using the English languages and then log out, I will be redirected to the french homepage. I tried changing the logout url, including the language part, like this:
"/login/login.mvc?logout=True?language=i18n_get_lang()"
, but no success. Any idea how to solve this would be more than welcome.
PS, the login redirection works correctly.
Below is my springSecurity.xml
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="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
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.0.xsd">
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/login/login.mvc" access="isAnonymous()" />
<!-- <intercept-url pattern="/admin**" access="ROLE_USER" /> -->
<form-login
login-processing-url="/login/login.mvc"
login-page="/login/login.mvc"
default-target-url="/login/accueil.mvc"
authentication-failure-url="/login/login.mvc?Error=True"
username-parameter="j_username"
password-parameter="j_password" />
<logout logout-success-url="/login/login.mvc?logout=True?language=localeChangeInterceptor"
logout-url="/login/j_spring_security_logout"/>
<!-- unable csrf protection -->
<csrf disabled="true"/>
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="user" password="1234" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
My MVC-servlet.xml
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/images/**" location="/images/" />
<mvc:resources mapping="/js/**" location="/js/" />
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:i18n/Message"/>
<property name="defaultEncoding" value="UTF-8"/>
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="fr" />
</bean>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="language" />
</bean>
<mvc:interceptors>
<!-- Changes the locale when a 'lang' request parameter is sent; e.g. /?lang=de -->
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="language"/>
</bean>
</mvc:interceptors>
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" >
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor" />
</list>
</property>
</bean>
</beans>
I found a solution: change SessionLocaleResolver to CookieLocaleResolver in MVC-servlet.xml.

xml schema for Springbatch3.0.1?

i am trying to accomplish spring batch in spring 3.0.1 and sufficient jars have been included in the class path.when i am trying to run the project with command line job runner i am getting a error that shows because of miss match xml schema for spring3.0.1. i have 3 differnt xml files as below
ApplicationContext.xml
<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
xsi:schemalocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<import resource="JobRepository.xml" />
</beans>
jobConfiguration.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<import resource="ApplicationContext.xml" />
<bean abstract="true"
class="org.springframework.batch.core.step.tasklet.TaskletStep" id="taskletStep">
<property name="jobRepository" ref="jobRepository" />
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean class="com.mypackage.HelloWorldTasklet" id="helloTasklet">
<property name="message" value="Hello World!" />
</bean>
<bean class="com.mypackage.HelloWorldTasklet" id="createdByTasklet">
<property name="message" value="Created By Harish On Java" />
</bean>
<bean class="org.springframework.batch.core.job.SimpleJob" id="mySimpleJob">
<property name="name" value="mySimpleJob" />
<property name="steps">
<list>
<bean parent="taskletStep">
<property name="tasklet" ref="helloTasklet" />
</bean>
<bean parent="taskletStep">
<property name="tasklet" ref="createdByTasklet" />
</bean>
</list>
</property>
<property name="jobRepository" ref="jobRepository" />
</bean>
</beans>
JobRepository.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
xsi:schemalocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<bean
class="org.springframework.batch.core.repository.support.SimpleJobRepository"
id="jobRepository">
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapJobInstanceDao" />
</constructor-arg>
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />
</constructor-arg>
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapStepExecutionDao" />
</constructor-arg>
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapExecutionContextDao" />
</constructor-arg>
</bean>
<bean id="transactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<bean class="org.springframework.batch.core.launch.support.SimpleJobLauncher"
id="jobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
</beans>
Java Code:
public class HelloWorldTasklet implements Tasklet {
private String message;
public void setMessage(String message) {
this.message = message;
}
#Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext context) throws Exception {
// TODO Auto-generated method stub
System.out.println(message);
return RepeatStatus.FINISHED;
}
}
my lib contained following jars
com.springsource.org.aopalliance-1.0.0.jar
com.springsource.org.apache.commons.lang-sources-2.1.0.jar
com.springsource.org.apache.commons.logging-1.1.1.jar
com.springsource.org.apache.log4j-1.2.15.jar
commons-beanutils-1.8.3.jar
commons-codec-1.3.jar
commons-collections-3.2.jar
commons-digester-1.8.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
org.springframework.aop-3.0.1.RELEASE-A.jar
org.springframework.asm-3.0.1.RELEASE-A.jar
org.springframework.aspects-3.0.1.RELEASE-A.jar
org.springframework.beans-3.0.1.RELEASE-A.jar
org.springframework.context-3.0.1.RELEASE-A.jar
org.springframework.context.support-3.0.1.RELEASE-A.jar
org.springframework.core-3.0.1.RELEASE-A.jar
org.springframework.expression-3.0.1.RELEASE-A.jar
org.springframework.web-3.0.1.RELEASE-A.jar
org.springframework.web.servlet-3.0.1.RELEASE-A.jar
spring-batch-core-2.2.0.RELEASE.jar
spring-batch-infrastructure-2.2.0.RELEASE.jar
any response is appreciated greatly in advance.
You have the Spring Batch 2.2.0.RELEASE jars on your classpath, yet you aren't specifying that version in your schemas. Update to use the versions and you'll be fine.
As a side note, is there a reason you are not using the schemas in your configuration? While you're configuring batch components, you're doing it the hard way by not using the namespace or factory beans. For example, instead of:
<bean
class="org.springframework.batch.core.repository.support.SimpleJobRepository"
id="jobRepository">
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapJobInstanceDao" />
</constructor-arg>
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />
</constructor-arg>
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapStepExecutionDao" />
</constructor-arg>
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapExecutionContextDao" />
</constructor-arg>
</bean>
you can do this:
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="transactionManager" ref="transactionManager"/>
</bean>
We also have namespace support for the job configuration. Instead of:
<bean class="org.springframework.batch.core.job.SimpleJob" id="mySimpleJob">
<property name="name" value="mySimpleJob" />
<property name="steps">
<list>
<bean parent="taskletStep">
<property name="tasklet" ref="helloTasklet" />
</bean>
<bean parent="taskletStep">
<property name="tasklet" ref="createdByTasklet" />
</bean>
</list>
</property>
<property name="jobRepository" ref="jobRepository" />
</bean>
you should try this:
<batch:job id="mySimpleJob">
<batch:step id="step1" next="step2">
<batch:tasklet ref="helloTasklet"/>
</batch:step>
<batch:step id="step2">
<batch:tasklet ref="createdByTasklet"/>
</batch:step>
</batch:job>
The namespaces handle some niceties like auto wiring the job repositories and transaction managers, etc. I'd recommend you take a look at the Spring Batch documentation here: http://docs.spring.io/spring-batch/2.2.x/reference/html/index.html

JBoss ESB XML MEP Behviour

I am using JBoss AS 5.1.0 and Jboss ESB 4.10
I am trying to Invoke a Service which has a single action. I have Set MEP = oneWay for the Service.
When I Invoke the Service Using the Below Method I do not get a reply but an Exception.
new ServiceInvoker("Chapter3Sample", "Chapter3Service").deliverSync(esbMessage, 10000);
WHen I change mep=RequestResponse : I am able to get the Reply
As per my understanding ESB Message has a ReplyTo field (Since I am invkoing a Sync Request) the Message should be returned back by the last Action which is not happening in my case. Please find below the ESB XML:
<?xml version="1.0"?>
<jbossesb parameterReloadSecs="5"
xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd http://anonsvn.jboss.org/repos/labs/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd">
<providers>
<jms-provider connection-factory="ConnectionFactory" name="JBossMQ">
<jms-bus busid="chapter3GwChannel">
<jms-message-filter dest-name="queue/chapter3_Request_gw" dest-type="QUEUE"/>
</jms-bus>
<jms-bus busid="chapter3EsbChannel">
<jms-message-filter dest-name="queue/chapter3_Request_esb" dest-type="QUEUE"/>
</jms-bus>
</jms-provider>
</providers>
<services>
<service category="Chapter3Sample"
description="A template for Chapter3" name="Chapter3Service">
<listeners>
<jms-listener busidref="chapter3GwChannel" is-gateway="true" name="Chapter3GwListener"/>
<jms-listener busidref="chapter3EsbChannel" name="Chapter3Listener"/>
</listeners>
<actions mep="OneWay">
<action class="org.jboss.soa.esb.samples.chapter3.MyAction"
name="BodyPrinter">
<property name="process" value="displayMessage"/>
<property name="symbol" value="*"/>
<property name="count" value="50"/>
<property name="propertyName">
<hierarchicalProperty attr="value">
<inner name="myName" random="randomValue"/>
</hierarchicalProperty>
</property>
<property name="exceptionMethod" value="processException"/>
<property name="okMethod" value="processSuccess"/>
</action>
</actions>
</service>
</services>
</jbossesb>
When your are invoking call as synchronus.
new ServiceInvoker("Chapter3Sample", "Chapter3Service").deliverSync(esbMessage, 10000).
set mep=RequestResponse.
when your are invoking call asynchronus.
new ServiceInvoker("Chapter3Sample", "Chapter3Service").deliverASync(esbMessage, 10000).
set mep=oneWay .

specify a database schema for activiti-5.12.1 tables

I am going to use activiti-5.12.1, in my project.
here is the activiti.cfg.xml file:
<?xml version='1.0' encoding='UTF-8'?>
<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.xsd">
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration" >
<property name="databaseType" value="postgres" />
<property name="jdbcUrl" value="jdbc:postgresql://project:5432/MYPROJECT" />
<property name="jdbcDriver" value="org.postgresql.Driver" />
<property name="jdbcUsername" value="me" />
<property name="jdbcPassword" value="you" />
<property name="databaseSchemaUpdate" value="false" />
<property name="jobExecutorActivate" value="false" />
<property name="history" value="full" />
<property name="customPreVariableTypes">
<list>
<ref bean="activitiScriptNodeType" />
<ref bean="activitiScriptNodeListType" />
</list>
</property>
<property name="mailServerHost" value="mail.my-corp.com" />
<property name="mailServerPort" value="5025" />
</bean>
</beans>
I want to create activiti database on my own, by using the scripts which are available in activiti-engine-5.12.1.jar.
By default, the tables are created in public schema, but I want them to be in another schema like mySchema for example.
my questioin is how can I manage this, besides, how can I specify this in activiti.cfg.xml, to inform activiti engine api that activiti tables are in mySchema?
I am using MySQL database for activiti, so i have got some configuration like this to creat my own schema name :
<property name="databaseType" value="mysql" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti" />
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="root" />
So as you using postgresql, i am not quite sure about whether the following code will work for you or not :
<?xml version='1.0' encoding='UTF-8'?>
<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.xsd">
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration" >
<property name="databaseType" value="postgres" />
<property name="jdbcUrl" value="jdbc:postgresql://project:5432/MYPROJECT/activiti" />
<property name="jdbcDriver" value="org.postgresql.Driver" />
<property name="jdbcUsername" value="me" />
<property name="jdbcPassword" value="you" />
<property name="databaseSchemaUpdate" value="false" />
<property name="jobExecutorActivate" value="false" />
<property name="history" value="full" />
<property name="customPreVariableTypes">
<list>
<ref bean="activitiScriptNodeType" />
<ref bean="activitiScriptNodeListType" />
</list>
</property>
<property name="mailServerHost" value="mail.my-corp.com" />
<property name="mailServerPort" value="5025" />
</bean>
Before deploying `activiti with new changes, mke sure that your database has the schema created.
Try changing the database's type to your database's name or "postgresql".
If you are using spring the below property helps:
spring.activiti.databaseSchema=MY_SCHEMA

Using Spring data JPA with MS SQL server

I am setting up an app using Spring data JPA, Hibernate and MS SQL Server and unfortunately, I got a beat messed up with the configurations.
I hope someone here code make things clearer:.
This is my mvc-dispatcher.xml which is the application context:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<context:component-scan base-package="com.yyy.yyy" />
<context:property-placeholder location="classpath:db.properties"/>
<!-- DATA BASE -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="true" />
<property name="database" value="SQL_SERVER" />
</bean>
</property>
<property name="persistenceUnitName" value="punit" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClass}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.user}" />
<property name="password" value="${jdbc.pwd}" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<jpa:repositories base-package="com.yyy.yyy.yyy.repository"/>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
Now, I also have a persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="punit">
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
<property name="hibernate.connection.url" value="${jdbc.url}" />
<property name="hibernate.connection.driver_class" value="${jdbc.driverClass}" />
<property name="hibernate.connection.username" value="${jdbc.user}" />
<property name="hibernate.connection.password" value="${jdbc.pwd}" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>
</persistence-unit>
</persistence>
I don't understand where should I put the DB connection data?
And I also cant connect to the DB (I get connection refused) - I am getting exception at server startup.
My project runs on Tomcat and I used https://github.com/SpringSource/spring-data-jpa-examples as a template.
EDIT
I managed to overcome the problems and publish to tomcat successfully,by removing the persistence XML file and use only the spring context file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:component-scan base-package="yyy.yyy.yyy" />
<context:property-placeholder location="classpath:db.properties" />
<!-- DATA BASE -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="yyy.yyy.yyy.yyy.domain" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="false" />
<property name="showSql" value="true" />
<property name="database" value="SQL_SERVER" />
<property name="databasePlatform" value="org.hibernate.dialect.SQLServerDialect" />
</bean>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver" />
<property name="url" value="jdbc:jtds:sqlserver://localhost;databaseName=db" />
<property name="username" value="yyy" />
<property name="password" value="yyyyy" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<jpa:repositories base-package="yyy.yyy.yyy.yyy.repository" />
<!-- MVC -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
The app now loads fine, but when I use my repository and call save, I get connection refused exception.
Anyone knows why?
Help please.
Idob
You are refering to db.properites file here:<context:property-placeholder location="classpath:db.properties"/>
Where is it located in the project?