tuscany-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gopi Lokavarapu <gopi.lokar...@gmail.com>
Subject Tuscany + Sring+Hibernate (tuscany 2.x + spring3.0.5-RELEASE +Hibernate 3.6
Date Tue, 11 Feb 2014 11:35:14 GMT
Could you plase provide solution for the following scenario.Since one week
I have struggling with this problem.

bigbank.composit
------------------------
<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
           xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
    targetNamespace="http://bigbank"
    xmlns:bb="http://bigbank"
    xmlns:bbsv="http://bigbank/savings"
    xmlns:bbst="http://bigbank/stock"
    xmlns:bbck="http://bigbank/checkings"
    xmlns:s="http://stockquote"
    name="BigBank">

    <component name="AccountServiceComponent">
        <implementation.spring
location="spring-context/Account-spring-context.xml"/>

        <service name="AccountService">
             <tuscany:binding.rest uri="/getAccountDetails">
            <tuscany:wireFormat.json/>
                <tuscany:operationSelector.jaxrs/>
                </tuscany:binding.rest >
        </service>

        <reference name="savingsAccountService"
target="SavingsAccountServiceComponent"/>

        <reference name="stockAccountService"
target="StockAccountServiceComponent"/>


        <reference name="stockQuoteService">
            <tuscany:binding.rest uri="
http://localhost:8080/services/StockQuoteWebService"/>
        </reference>

    </component>

savingsaccount.composite
---------------------------------------
<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
           xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
    targetNamespace="http://bigbank/savings"
    xmlns:bbsv="http://bigbank/savings"
    name="SavingsAccountDept">


    <service name="SavingsAccountService"
promote="SavingsAccountServiceComponent"/>
    <component name="SavingsAccountServiceComponent">
        <implementation.spring
location="spring-context/SavingsAccount-context.xml"/>

    </component>

</composite>
stockaccount.composite
--------------------------------
 <composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
           xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
    targetNamespace="http://bigbank/stock"
    xmlns:bbst="http://bigbank/stock"
    name="StockAccountDept">

    <service name="StockAccountService"
promote="StockAccountServiceComponent"/>
    <component name="StockAccountServiceComponent">
        <implementation.spring
location="spring-context/META-INF/spring/StockQuoteService-context.xml"/>

    </component>

</composite>

and corresponding spring aplication context files
SavingsAccount-context.xml
-----------------------------------------
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:sca="http://www.springframework.org/schema/sca"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/sca
http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd">

    <sca:service name="SavingsAccountService"
        type="bigbank.account.savings.SavingsAccountService"
target="SavingsAccountServiceBean"/>

    <bean id="SavingsAccountServiceBean"
class="bigbank.account.savings.SavingsAccountServiceImpl">
    </bean>

</beans>

Account-context.xml
------------------------------
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:sca="http://www.springframework.org/schema/sca"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/sca
http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd">
<import resource=""/>
    <sca:service name="AccountService"
        type="bigbank.account.AccountService" target="AccountServiceBean"/>

    <bean id="AccountServiceBean"
class="bigbank.account.AccountServiceImpl">
        <!-- <property name="calculatorService" ref="calculatorService"/>
-->
        <property name="stockQuoteService" ref="stockQuoteService"/>
       <!--  <property name="checkingAccountService"
ref="checkingAccountService"/>
         -->
        <!-- Here are some implicit references & properties - a property
with a ref not satisifed
        * within the Spring application context.
         -->
        <property name="savingsAccountService" ref="savingsAccountService"/>
        <property name="stockAccountService"
ref="stockAccountService"/>
        <property name="currency" value="EURO"/>
    </bean>

    <!-- <sca:reference name="checkingAccountService"
type="bigbank.account.checking.CheckingAccountService"/>

    <sca:reference name="calculatorService"
type="bigbank.calculator.CalculatorService"/>
    -->
    <sca:reference name="stockQuoteService"
type="bigbank.stockquote.StockQuoteService"/>

    <sca:reference name="savingsAccountService"
type="bigbank.account.savings.SavingsAccountService"/>

    <sca:reference name="stockAccountService"
type="bigbank.account.stock.StockAccountService"/>

</beans>

StockAccount-context.xml
-------------------------------------
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:sca="http://www.springframework.org/schema/sca"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/sca
http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd">

    <sca:service name="StockQuoteService"
        type="bigbank.stockquote.StockQuoteService"
target="StockQuoteServiceBean"/>

    <bean id="StockQuoteServiceBean"
class="bigbank.stockquote.StockQuoteImpl">
    </bean>

    <!-- <bean id="applicationContextProvider"
class="bigbank.stockquote.server.SCAApplicationContextProvider"/> -->

</beans>

And another spring application context is there
for dao's and sessionfactory
ApplicationContext.xml
---------------------------------

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="
http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="
http://www.springframework.org/schema/aop"
    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/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                        http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">

    <!-- spring based txmngmt -->
    <tx:annotation-driven />
    <context:annotation-config />
     <context:property-placeholder
location="classpath:properties/hibernate.properties"/>

    <!-- <bean

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="properties/hibernate.properties" />
    </bean>
 -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="${driverClass}" />
        <property name="url" value="${url}" />
        <property name="username" value="${username}" />
        <property name="password" value="${password}" />
    </bean>

    <bean id="sessionFactory"

class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>


        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hbm2ddl.auto">${hbm2ddl.auto}</prop>

                <prop
key="hibernate.connection.zeroDateTimeBehavior">${hibernate.connection.zeroDateTimeBehavior}</prop>

                <prop key="hibernate.cache.provider_class">${class}</prop>
                <prop
key="hibernate.cache.use_second_level_cache">${second_level_cache}</prop>
                <prop
key="hibernate.cache.use_structured_entries">${structured_entries}</prop>
                <prop
key="hibernate.cache.use_query_cache">${query_cache}</prop>

                <!-- Hibernate Connection Pooling -->
                <prop key="hibernate.c3p0.min_size">${min_size}</prop>
                <prop
key="hibernate.c3p0.acquire_increment">${increment}</prop>
                <prop key="hibernate.c3p0.max_size">${max_size}</prop>
                <prop key="hibernate.c3p0.timeout">${timeout}</prop>
                <prop
key="hibernate.c3p0.idle_test_period">${test_period}</prop>
            </props>
        </property>

    </bean>


   <context:component-scan base-package="bigbank.account.dao"/>

    <bean id="transactionManager"

class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>


    </beans>

Note:Here my problem was when injecting Dao class to Account service class
it is not injecting how can i get the scope of this application context to
remaing sca spring application contexts


import java.util.ArrayList;
import java.util.List;

import org.oasisopen.sca.annotation.Destroy;
import org.oasisopen.sca.annotation.Init;
import org.oasisopen.sca.annotation.Reference;
import org.oasisopen.sca.annotation.Scope;
import org.oasisopen.sca.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import bigbank.account.checking.CheckingAccountDetails;
import bigbank.account.dao.AccountDao;
import bigbank.account.savings.SavingsAccountDetails;
import bigbank.account.savings.SavingsAccountService;
import bigbank.account.stock.StockAccountDetails;
import bigbank.account.stock.StockAccountService;
import bigbank.stockquote.StockQuoteService;

/**
 * Account service implementation
 */

@Service(AccountService.class)
public class AccountServiceImpl implements AccountService {

    public AccountServiceImpl(){
        System.out.println("AccountServiceImpl");
    }

    @Init
    public void init(){
        System.out.println("init");
    }

    @Destroy
    public void destroy(){
        System.out.println("destroy");
    }


    private SavingsAccountService savingsAccountService;


    /*private CheckingAccountService checkingAccountService;*/


    private StockAccountService stockAccountService;


    private AccountDao accountDao;//here is the problem it is not injecting

how to inject dao classes in services of tuscany.

    @Autowired
    public void setAccountDao(AccountDao accountDao){
        this.accountDao=accountDao;
        System.out.println("account dao"+accountDao);
    }

    public AccountDao getAccountDao(){
        return accountDao;
    }

   /* private CalculatorService calculatorService;
    */


    private StockQuoteService stockQuoteService;

    private String currency;

    public AccountReport getAccountReport(String id) {
        System.out.println("account dao"+accountDao);
        // Get the checking, savings and stock accounts from the AccountData
        // service component
        CheckingAccountDetails checking = null;
        List<String> summaries = new ArrayList<String>();
        try {
           // checking =
checkingAccountService.getAccountDetails(customerID);
            System.out.println("Checking account: " + checking);
            //summaries.add(checking.toString());
System.out.println("AccountServiceImpl:getAccount");
            SavingsAccountDetails savings =
savingsAccountService.getAccountDetails(id);
            System.out.println("Savings account: " + savings);
            summaries.add(savings.toString());

            StockAccountDetails stock =
stockAccountService.getAccountDetails(id);
            System.out.println("Stock account: " + stock);
            summaries.add(stock.toString());

System.out.println("accountDao.getData();"+accountDao.getData());
            // Get the stock price in USD
            double price = stockQuoteService.getQuote(stock.getSymbol());
            System.out.println("Stock price for " + stock.getSymbol() + ":
" + price);

            // Convert to the configured currency
            if (currency.equals("EURO")) {

                // Use our fancy calculator service to convert to the
target currency
               // price = calculatorService.multiply(price, 0.70);

              //  System.out.println("Converted to " + currency + ": " +
price);
            }

            // Calculate the value of the stock account
           // double stockValue = price * stock.getQuantity();
            summaries.add(stock.toString());

            AccountReport report = new AccountReport(currency, summaries);

            return report;
        } catch ( Throwable e ) {
            e.printStackTrace();
            return null;
        }
    }

    public SavingsAccountService getSavingsAccountService() {
        return savingsAccountService;
    }

    public void setSavingsAccountService(SavingsAccountService
savingsAccountService) {

System.out.println("savingsAccountService-injection"+savingsAccountService);
        this.savingsAccountService = savingsAccountService;
    }

   /* public CheckingAccountService getCheckingAccountService() {
        return checkingAccountService;
    }

    public void setCheckingAccountService(CheckingAccountService
checkingAccountService) {
        this.checkingAccountService = checkingAccountService;
    }*/

    public StockAccountService getStockAccountService() {
        return stockAccountService;
    }

    public void setStockAccountService(StockAccountService
stockAccountService) {

System.out.println("stockAccountService-injection"+stockAccountService);
        this.stockAccountService = stockAccountService;
    }

    public String getCurrency() {
        return currency;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }

   /* public CalculatorService getCalculatorService() {
        return calculatorService;
    }

    public void setCalculatorService(CalculatorService calculatorService) {
        this.calculatorService = calculatorService;
    }
*/
    public StockQuoteService getStockQuoteService() {
        return stockQuoteService;
    }

    public void setStockQuoteService(StockQuoteService stockQuoteService) {
        System.out.println("stockQuoteService-injection"+stockQuoteService);
        this.stockQuoteService = stockQuoteService;
    }
}

Mime
View raw message