Advertisement
Guest User

Untitled

a guest
Nov 25th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. public void printData()
  2. {
  3. System.out.println("just to test aspect programming");
  4. }
  5.  
  6. @RequestMapping("/")
  7. public String doLogin(ModelMap modelMap)
  8. {
  9. System.out.println("doLogin" +loginService);
  10.  
  11. String message=messageSource.getMessage("message", null, "default", Locale.UK);
  12. System.out.println("Message is:" + message);
  13. printData();
  14. LoginForm loginForm=new LoginForm();
  15. modelMap.put("loginForm",loginForm);
  16. return "login";
  17. }
  18.  
  19. My Aspect class is as follows:
  20. package com.neha.javabrains;
  21.  
  22. import org.springframework.stereotype.Component;
  23. import org.aspectj.lang.ProceedingJoinPoint;
  24. import org.aspectj.lang.annotation.Around;
  25. import org.aspectj.lang.annotation.Aspect;
  26. import org.aspectj.lang.annotation.Before;
  27. import org.aspectj.lang.annotation.Pointcut;
  28.  
  29. @Component
  30. @Aspect
  31. public class LogTime {
  32.  
  33. @Before("execution(* com.neha.javabrains.LoginController.printData(..))")
  34. public void loggedData()
  35. {
  36. System.out.println("In Pointcut Expression");
  37. }
  38. }
  39.  
  40. <?xml version="1.0" encoding="UTF-8"?>
  41.  
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43. xmlns:context="http://www.springframework.org/schema/context"
  44. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  45. xmlns:mvc="http://www.springframework.org/schema/mvc"
  46. xmlns:tx="http://www.springframework.org/schema/tx"
  47. xmlns:aop="http://www.springframework.org/schema/aop"
  48. xsi:schemaLocation="
  49. http://www.springframework.org/schema/beans
  50. http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  51. http://www.springframework.org/schema/context
  52. http://www.springframework.org/schema/context/spring-context-4.0.xsd
  53. http://www.springframework.org/schema/mvc
  54. http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
  55. http://www.springframework.org/schema/tx
  56. http://www.springframework.org/schema/tx/spring-tx.xsd
  57. http://www.springframework.org/schema/aop
  58. http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
  59.  
  60. <!-- <bean/> definitions here -->
  61. <context:component-scan base-package="com.neha.javabrains" />
  62. <context:annotation-config/>
  63. <mvc:annotation-driven />
  64. <mvc:default-servlet-handler />
  65.  
  66. <mvc:resources mapping="/resources/**" location="/resources/" />
  67. <tx:annotation-driven transaction-manager="txManager"/>
  68. <aop:aspectj-autoproxy />
  69.  
  70. <bean id="loginDAO" class="com.neha.javabrains.LoginDAO">
  71. <property name="hibernateTemplate" ref="hibernateTemplate"></property>
  72. </bean>
  73.  
  74. <bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
  75. <property name="sessionFactory" ref="mySessionFactory"/>
  76. </bean>
  77.  
  78. <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  79. <property name="dataSource" ref="myDataSource"/>
  80. </bean>
  81.  
  82. <bean id="loginFormValidator" class="com.neha.javabrains.LoginFormValidator"/>
  83.  
  84. <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
  85. <property name="basename" value="message" />
  86. <property name="defaultEncoding" value="UTF-8" />
  87. </bean>
  88.  
  89. <beans profile="dev">
  90. <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  91. <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
  92. <property name="url" value="jdbc:oracle:thin:@localhost:1521:books"></property>
  93. <property name="username" value="system"></property>
  94. <property name="password" value="xyz"></property>
  95. </bean>
  96. </beans>
  97.  
  98. <beans profile="prod">
  99. <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  100. <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
  101. <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"></property>
  102. <property name="username" value="system"></property>
  103. <property name="password" value="abc"></property>
  104. </bean>
  105. </beans>
  106.  
  107. </beans>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement