How to write ApplicationContext xml equivalent java code

55
January 12, 2019, at 4:50 PM

I want to make java based configuration. I have already xml configuration in my project and it's worked. can any one give java based example equivalent bellow ApplicationContext.xml

I am trying so many way but didn't get success; followed this link: https://www.boraji.com/spring-mvc-5-spring-security-5-hibernate-5-example

Dao Interface:

public interface UserDao extends GenericDao<User, String>{   

}

Dao Implementation:

public class UserDaoImpl extends GenericDaoImpl<User, String> implements   UserDao {
public UserDaoImpl() {
    super(User.class);
}

}

ApplicationContext.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:mvc="http://www.springframework.org/schema/mvc"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:util="http://www.springframework.org/schema/util"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd 
   http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
   http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
      p:location="classpath:database.properties" />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
      p:driverClassName="${database.driverClassName}"
      p:url="${database.url}"
      p:username="${database.username}"
      p:password="${database.password}" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation">
        <value>classpath:hibernate.cfg.xml</value>
    </property>
    <property name="hibernateProperties">  
        <props> 
            <prop key="current_session_context_class">thread</prop>  
            <prop key="hibernate.show_sql">true</prop>
            <prop key="fomat_sql">true</prop>  
            <prop key="hibernate.hbm2ddl.auto">none</prop>
            <prop key="hibernate.connection.SetBigStringTryBlob">true</prop>
            <prop key="hibernate.connection.autocommit">true</prop> 
            <prop key="hibername.jdbc.batch_size">0</prop> 
        </props>  
    </property>  
</bean>
<bean id = "transactionManager" class = "org.springframework.orm.hibernate5.HibernateTransactionManager">
    <property name = "sessionFactory" ref = "sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="userDao" class="com.am.it.repository.UserDaoImpl">
    <property name="sessionFactory">
        <ref bean="sessionFactory"/>
    </property>
</bean> 

This xml configuration worked for me, but need Java Code from xml configuration.

READ ALSO
How to fix &ldquo;mainflipSelectors[i].find&rdquo; error in jQuery?

How to fix “mainflipSelectors[i].find” error in jQuery?

I am building a webpage where I need to display some details about a few peopleEach person's details is in the form of a card which goes by this structure:

54
How to use barcode scanner as keyboard input

How to use barcode scanner as keyboard input

I'm using model PowerScan PD1700 (Datalogic brand)I have 2 problems:

63
PM2 cron running every second

PM2 cron running every second

I'm using the --cron flag to run a job every hourThe issue is as soon as I deploy using pm2 deploy

30