Announcement Announcement Module
Collapse
No announcement yet.
how should I migrate this source code for spring 3.x? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how should I migrate this source code for spring 3.x?

    package aop;


    import org.aopalliance.intercept.MethodInterceptor;
    import org.aopalliance.intercept.MethodInvocation;

    public class OperacaoAdvice implements MethodInterceptor {

    public Object invoke(MethodInvocation methodInvocation) throws Throwable {

    System.out.println("AOP -> Método chamado: " + methodInvocation.getMethod().getName());
    Object object = null;

    try {
    object = methodInvocation.proceed();
    System.out.println(object);

    return object;

    }catch (Exception e) {
    // TODO: handle exception
    }

    return object;
    }
    }

    package aop;
    import java.lang.reflect.Method;

    import org.springframework.aop.AfterReturningAdvice;

    public class RecuperacaoListasAdvice implements
    AfterReturningAdvice {
    public void afterReturning(Object returnValue, Method metodo,
    Object[] arg2, Object target) throws Throwable {

    Object lista = returnValue;
    System.out.println("AOP -> A lista retornou " + lista + " objetos.");

    }
    }


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

    <hibernate-mapping package="banco">

    <class name="Banco" table="TB_BANCO" lazy="false">
    <id name="id" type="java.lang.Long" column="ID">
    <generator class="native" />
    </id>
    <property name="nome" column="NOME" type="java.lang.String"
    length="50" unique="true" />
    </class>

    </hibernate-mapping>

    package banco;

    import java.io.Serializable;

    @SuppressWarnings("serial")
    public class Banco implements Serializable {

    private Long id;
    private String nome;

    public Banco() {

    }

    public Long getId() {
    return id;
    }

    public void setId(Long id) {
    this.id = id;
    }

    public String getNome() {
    return nome;
    }

    public void setNome(String nome) {
    this.nome = nome;
    }

    public String toString() {
    return id + " - " + nome;
    }
    }

    package banco;

    public interface BancoDao {

    public void salvarBanco(Banco banco);
    }

    package banco;

    import org.springframework.orm.hibernate3.support.Hiberna teDaoSupport;

    public class BancoImp extends HibernateDaoSupport implements BancoDao {

    @Override
    public void salvarBanco(Banco banco) {
    getHibernateTemplate().saveOrUpdate(banco);
    }
    }



    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>

    <!-- ************************************************** *************************************************
    Configuração AOP: spring framework
    ************************************************** ************************************************** -->

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName"> <value>org.hsqldb.jdbcDriver</value>
    </property> <property name="url"> <value>jdbc:hsqldb:database/tutorial/db_sistema</value>
    </property> <property name="username"> <value>sa</value> </property> <property
    name="password"> <value></value> </property>
    </bean>

    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    <property name="mappingResources">
    <list>
    <value>banco/Banco.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.max_fetch_depth">2</prop>
    <prop key="hibernate.hbm2ddl.auto">create</prop>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
    <prop key="hibernate.dialect">org.hibernate.dialect.HSQL Dialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.current_session_context_class">thre ad</prop>
    <prop key="hibernate.cache.provider_class">org.hibernate .cache.NoCacheProvider</prop>
    <prop key="hibernate.c3p0.minPoolSize">5</prop>
    <prop key="hibernate.c3p0.maxPoolSize">20</prop>
    <prop key="hibernate.c3p0.timeout">600</prop>
    <prop key="hibernate.c3p0.max_statement">50</prop>
    <prop key="hibernate.c3p0.testConnectionOnCheckout">fals e</prop>
    </props>
    </property>
    </bean>

    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>

    <!-- ************************************************** *************************************************
    Configuração AOP: spring framework
    ************************************************** ************************************************** -->

    <bean id="operacaoAdvice" class="aop.OperacaoAdvice"></bean>
    <bean id="recuperacaoListasAdvice" class="aop.RecuperacaoListasAdvice"></bean>

    <bean id="operacaoPointcutAdvisor"
    class="org.springframework.aop.support.NameMatchMe thodPointcutAdvisor">
    <property name="mappedNames">
    <list>
    <value>save*</value>
    <value>remove*</value>
    </list>
    </property>
    <property name="advice">
    <ref bean="operacaoAdvice" />
    </property>
    </bean>

    <bean id="recuperacaoListasPointcutAdvisor"
    class="org.springframework.aop.support.NameMatchMe thodPointcutAdvisor">
    <property name="mappedName">
    <value>pegar*</value>
    </property>
    <property name="advice">
    <ref bean="recuperacaoListasAdvice" />
    </property>
    </bean>


    <!-- ************************************************** *************************************************
    Configuração AOP: banco
    ************************************************** ************************************************** -->

    <bean id="bancoImpFachadaTarget" class="banco.BancoImp">
    <property name="sessionFactory">
    <ref local="sessionFactory" />
    </property>
    </bean>

    <bean id="bancoFachadaService" class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="target">
    <ref bean="bancoImpFachadaTarget" />
    </property>
    </bean>

    </beans>


    package principal;

    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlAp plicationContext;

    import banco.Banco;
    import banco.BancoDao;
    import banco.BancoImp;

    public class Sistema {

    private BancoDao bancoDao;
    private Banco banco;

    private static ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
    "classpathrincipal/applicationContext.xml");

    public Sistema() {

    banco = new Banco();
    banco.setNome("Bradesco");

    bancoDao = (BancoImp) applicationContext
    .getBean("bancoFachadaService");
    bancoDao.salvarBanco(banco);

    System.out.println(banco);
    }

    public static void main(String[] args) {
    Sistema sistema = new Sistema();

    }
    }

  • #2
    I would first try converting the applicationContext.xml to use the latest xml schema instead of the older DTD.

    Do you have a lot of older code that needs to be converted over to Spring 3.0?

    You might want to try to generate a skeleton project with Spring Roo and then play around with it and see what the differences are among your project and the Spring 3.0 stuff.

    What version of Spring are you trying migrate from?

    Comment


    • #3
      I'll start a new project for desktop application.
      This code is for version 1.x of Spring.
      I'm starting with a team of programmers here in Brazil to develop an ERP system.
      In fact it is well underway but we need to implement code with Spring 3.x.
      If we get this code in version 3 of Spring our company will achieve better results.
      And it will help greatly in our future projects with the spring.
      The project already has about 250,000 lines of code.
      If someone manages to make the migration of code placed here on the forum so spring 3, we appreciate.

      Comment


      • #4
        Originally posted by nelsonfosgate1
        +1 to the 1st comment, that is what you need to do
        Eu preciso que este código funciona com as bibliotecas do Spring 3.
        O problema é que o código postado, só funciona com as bibliotecas do Spring 1.

        I need this code works with the libraries of Spring 3.
        The problem is that the code posted works only with libraries of Spring 1.

        Comment

        Working...
        X