2024-01 spring-04-aop

This commit is contained in:
Vladimir Ivanov
2024-02-14 19:51:07 +03:00
parent 9696835b18
commit f8b963ca41
2 changed files with 0 additions and 56 deletions
@@ -1,25 +0,0 @@
package ru.otus.spring.dao;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class DaoConfig {
@Bean
Object getObject() {
Object o = new Object();
System.out.println("Create new: " + o);
return o;
}
@Bean
PersonDao getPersonDao1() {
return new PersonDaoObject(this.getObject());
}
@Bean
PersonDao getPersonDao2() {
return new PersonDaoObject(this.getObject());
}
}
@@ -1,31 +0,0 @@
package ru.otus.spring.dao;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;
import ru.otus.spring.domain.Person;
@Primary
@Repository
public class PersonDaoObject implements PersonDao {
public PersonDaoObject() {
}
public PersonDaoObject(Object object) {
System.out.println("Create dao: " + this + " with " + object);
}
@Override
public Person findByName(String name) {
Person person = new Person(name, 18);
System.out.println("Dao findByName: " + name + ", person: " + person);
return person;
}
@Override
public void save(Person p) {
Person byName = findByName(p.getName());
System.out.println("Dao save: " + p + ", findByName: " + byName);
}
}