Commit 7f4fae33 authored by John Lam's avatar John Lam

spring big picture demos

parent 1c63978d
File added
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pluralsight</groupId>
<artifactId>conference</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
import com.pluralsight.service.SpeakerService;
import com.pluralsight.service.SpeakerServiceImpl;
public class Application {
public static void main(String args[]) {
SpeakerService service = new SpeakerServiceImpl();
System.out.println(service.findAll().get(0).getFirstName());
}
}
package com.pluralsight.model;
public class Speaker {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
package com.pluralsight.repository;
import com.pluralsight.model.Speaker;
import java.util.ArrayList;
import java.util.List;
public class HibernateSpeakerRepositoryImpl implements SpeakerRepository {
public List<Speaker> findAll() {
List<Speaker> speakers = new ArrayList<Speaker>();
Speaker speaker = new Speaker();
speaker.setFirstName("Bryan");
speaker.setLastName("Hansen");
speakers.add(speaker);
return speakers;
}
}
package com.pluralsight.repository;
import com.pluralsight.model.Speaker;
import java.util.List;
public interface SpeakerRepository {
List<Speaker> findAll();
}
package com.pluralsight.service;
import com.pluralsight.model.Speaker;
import java.util.List;
public interface SpeakerService {
List<Speaker> findAll();
}
package com.pluralsight.service;
import com.pluralsight.model.Speaker;
import com.pluralsight.repository.HibernateSpeakerRepositoryImpl;
import com.pluralsight.repository.SpeakerRepository;
import java.util.List;
public class SpeakerServiceImpl implements SpeakerService {
private SpeakerRepository repository = new HibernateSpeakerRepositoryImpl();
public List<Speaker> findAll() {
return repository.findAll();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pluralsight</groupId>
<artifactId>conference-java</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
import com.pluralsight.repository.HibernateSpeakerRepositoryImpl;
import com.pluralsight.repository.SpeakerRepository;
import com.pluralsight.service.SpeakerService;
import com.pluralsight.service.SpeakerServiceImpl;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
@Configuration
@ComponentScan({"com.pluralsight"})
public class AppConfig {
/*
@Bean(name = "speakerService")
@Scope(value= BeanDefinition.SCOPE_SINGLETON)
public SpeakerService getSpeakerService() {
//SpeakerServiceImpl service = new SpeakerServiceImpl(getSpeakerRepository());
SpeakerServiceImpl service = new SpeakerServiceImpl();
//service.setRepository(getSpeakerRepository());
return service;
}
@Bean(name = "speakerRepository")
public SpeakerRepository getSpeakerRepository() {
return new HibernateSpeakerRepositoryImpl();
}*/
}
import com.pluralsight.service.SpeakerService;
import com.pluralsight.service.SpeakerServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Application {
public static void main(String args[]) {
ApplicationContext appContext = new AnnotationConfigApplicationContext(AppConfig.class);
//SpeakerService service = new SpeakerServiceImpl();
SpeakerService service = appContext.getBean("speakerService", SpeakerService.class);
System.out.println(service);
System.out.println(service.findAll().get(0).getFirstName());
SpeakerService service2 = appContext.getBean("speakerService", SpeakerService.class);
System.out.println(service2);
}
}
package com.pluralsight.model;
public class Speaker {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
package com.pluralsight.repository;
import com.pluralsight.model.Speaker;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
@Repository("speakerRepository")
public class HibernateSpeakerRepositoryImpl implements SpeakerRepository {
public List<Speaker> findAll() {
List<Speaker> speakers = new ArrayList<Speaker>();
Speaker speaker = new Speaker();
speaker.setFirstName("Bryan");
speaker.setLastName("Hansen");
speakers.add(speaker);
return speakers;
}
}
package com.pluralsight.repository;
import com.pluralsight.model.Speaker;
import java.util.List;
public interface SpeakerRepository {
List<Speaker> findAll();
}
package com.pluralsight.service;
import com.pluralsight.model.Speaker;
import java.util.List;
public interface SpeakerService {
List<Speaker> findAll();
}
package com.pluralsight.service;
import com.pluralsight.model.Speaker;
import com.pluralsight.repository.HibernateSpeakerRepositoryImpl;
import com.pluralsight.repository.SpeakerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("speakerService")
public class SpeakerServiceImpl implements SpeakerService {
private SpeakerRepository repository;
public SpeakerServiceImpl() {
System.out.println("SpeakServiceImpl no args constructor");
}
public SpeakerServiceImpl (SpeakerRepository speakerRepository) {
System.out.println("SpeakServiceImpl repository constructor");
repository = speakerRepository;
}
public List<Speaker> findAll() {
return repository.findAll();
}
public void setRepository(SpeakerRepository repository) {
System.out.println("SpeakServiceImpl setter");
this.repository = repository;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pluralsight</groupId>
<artifactId>conference</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
import com.pluralsight.service.SpeakerService;
import com.pluralsight.service.SpeakerServiceImpl;
public class Application {
public static void main(String args[]) {
SpeakerService service = new SpeakerServiceImpl();
System.out.println(service.findAll().get(0).getFirstName());
}
}
package com.pluralsight.model;
public class Speaker {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
package com.pluralsight.repository;
import com.pluralsight.model.Speaker;
import java.util.ArrayList;
import java.util.List;
public class HibernateSpeakerRepositoryImpl implements SpeakerRepository {
public List<Speaker> findAll() {
List<Speaker> speakers = new ArrayList<Speaker>();
Speaker speaker = new Speaker();
speaker.setFirstName("Bryan");
speaker.setLastName("Hansen");
speakers.add(speaker);
return speakers;
}
}
package com.pluralsight.repository;
import com.pluralsight.model.Speaker;
import java.util.List;
public interface SpeakerRepository {
List<Speaker> findAll();
}
package com.pluralsight.service;
import com.pluralsight.model.Speaker;
import java.util.List;
public interface SpeakerService {
List<Speaker> findAll();
}
package com.pluralsight.service;
import com.pluralsight.model.Speaker;
import com.pluralsight.repository.HibernateSpeakerRepositoryImpl;
import com.pluralsight.repository.SpeakerRepository;
import java.util.List;
public class SpeakerServiceImpl implements SpeakerService {
private SpeakerRepository repository = new HibernateSpeakerRepositoryImpl();
public List<Speaker> findAll() {
return repository.findAll();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pluralsight</groupId>
<artifactId>conference</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
import com.pluralsight.service.SpeakerService;
import com.pluralsight.service.SpeakerServiceImpl;
public class Application {
public static void main(String args[]) {
SpeakerService service = new SpeakerServiceImpl();
System.out.println(service.findAll().get(0).getFirstName());
}
}
package com.pluralsight.model;
public class Speaker {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
package com.pluralsight.repository;
import com.pluralsight.model.Speaker;
import java.util.ArrayList;
import java.util.List;
public class HibernateSpeakerRepositoryImpl implements SpeakerRepository {
public List<Speaker> findAll() {
List<Speaker> speakers = new ArrayList<Speaker>();
Speaker speaker = new Speaker();
speaker.setFirstName("Bryan");
speaker.setLastName("Hansen");
speakers.add(speaker);
return speakers;
}
}
package com.pluralsight.repository;
import com.pluralsight.model.Speaker;
import java.util.List;
public interface SpeakerRepository {
List<Speaker> findAll();
}
package com.pluralsight.service;
import com.pluralsight.model.Speaker;
import java.util.List;
public interface SpeakerService {
List<Speaker> findAll();
}
package com.pluralsight.service;
import com.pluralsight.model.Speaker;
import com.pluralsight.repository.HibernateSpeakerRepositoryImpl;
import com.pluralsight.repository.SpeakerRepository;
import java.util.List;
public class SpeakerServiceImpl implements SpeakerService {
private SpeakerRepository repository = new HibernateSpeakerRepositoryImpl();
public List<Speaker> findAll() {
return repository.findAll();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pluralsight</groupId>
<artifactId>conference-java</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
import com.pluralsight.repository.HibernateSpeakerRepositoryImpl;
import com.pluralsight.repository.SpeakerRepository;
import com.pluralsight.service.SpeakerService;
import com.pluralsight.service.SpeakerServiceImpl;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
@Configuration
@ComponentScan({"com.pluralsight"})
public class AppConfig {
/*
@Bean(name = "speakerService")
@Scope(value= BeanDefinition.SCOPE_SINGLETON)
public SpeakerService getSpeakerService() {
//SpeakerServiceImpl service = new SpeakerServiceImpl(getSpeakerRepository());
SpeakerServiceImpl service = new SpeakerServiceImpl();
//service.setRepository(getSpeakerRepository());
return service;
}
@Bean(name = "speakerRepository")
public SpeakerRepository getSpeakerRepository() {
return new HibernateSpeakerRepositoryImpl();
}*/
}
import com.pluralsight.service.SpeakerService;
import com.pluralsight.service.SpeakerServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Application {
public static void main(String args[]) {
ApplicationContext appContext = new AnnotationConfigApplicationContext(AppConfig.class);
//SpeakerService service = new SpeakerServiceImpl();
SpeakerService service = appContext.getBean("speakerService", SpeakerService.class);
System.out.println(service);
System.out.println(service.findAll().get(0).getFirstName());
SpeakerService service2 = appContext.getBean("speakerService", SpeakerService.class);
System.out.println(service2);
}
}
package com.pluralsight.model;
public class Speaker {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
package com.pluralsight.repository;
import com.pluralsight.model.Speaker;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
@Repository("speakerRepository")
public class HibernateSpeakerRepositoryImpl implements SpeakerRepository {
public List<Speaker> findAll() {
List<Speaker> speakers = new ArrayList<Speaker>();
Speaker speaker = new Speaker();
speaker.setFirstName("Bryan");
speaker.setLastName("Hansen");
speakers.add(speaker);
return speakers;
}
}
package com.pluralsight.repository;
import com.pluralsight.model.Speaker;
import java.util.List;
public interface SpeakerRepository {
List<Speaker> findAll();
}
package com.pluralsight.service;
import com.pluralsight.model.Speaker;
import java.util.List;
public interface SpeakerService {
List<Speaker> findAll();
}
package com.pluralsight.service;
import com.pluralsight.model.Speaker;
import com.pluralsight.repository.HibernateSpeakerRepositoryImpl;
import com.pluralsight.repository.SpeakerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("speakerService")
public class SpeakerServiceImpl implements SpeakerService {
private SpeakerRepository repository;
public SpeakerServiceImpl() {
System.out.println("SpeakServiceImpl no args constructor");
}
public SpeakerServiceImpl (SpeakerRepository speakerRepository) {
System.out.println("SpeakServiceImpl repository constructor");
repository = speakerRepository;
}
public List<Speaker> findAll() {
return repository.findAll();
}
public void setRepository(SpeakerRepository repository) {
System.out.println("SpeakServiceImpl setter");
this.repository = repository;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pluralsight</groupId>
<artifactId>conference</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
import com.pluralsight.service.SpeakerService;
import com.pluralsight.service.SpeakerServiceImpl;
public class Application {
public static void main(String args[]) {
SpeakerService service = new SpeakerServiceImpl();
System.out.println(service.findAll().get(0).getFirstName());
}
}
package com.pluralsight.model;
public class Speaker {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
package com.pluralsight.repository;
import com.pluralsight.model.Speaker;
import java.util.ArrayList;
import java.util.List;
public class HibernateSpeakerRepositoryImpl implements SpeakerRepository {
public List<Speaker> findAll() {
List<Speaker> speakers = new ArrayList<Speaker>();
Speaker speaker = new Speaker();
speaker.setFirstName("Bryan");
speaker.setLastName("Hansen");
speakers.add(speaker);
return speakers;
}
}
package com.pluralsight.repository;
import com.pluralsight.model.Speaker;
import java.util.List;
public interface SpeakerRepository {
List<Speaker> findAll();
}
package com.pluralsight.service;
import com.pluralsight.model.Speaker;
import java.util.List;
public interface SpeakerService {
List<Speaker> findAll();
}
package com.pluralsight.service;
import com.pluralsight.model.Speaker;
import com.pluralsight.repository.HibernateSpeakerRepositoryImpl;
import com.pluralsight.repository.SpeakerRepository;
import java.util.List;
public class SpeakerServiceImpl implements SpeakerService {
private SpeakerRepository repository = new HibernateSpeakerRepositoryImpl();
public List<Speaker> findAll() {
return repository.findAll();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pluralsight</groupId>
<artifactId>conference</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
import com.pluralsight.service.SpeakerService;
import com.pluralsight.service.SpeakerServiceImpl;
public class Application {
public static void main(String args[]) {
SpeakerService service = new SpeakerServiceImpl();
System.out.println(service.findAll().get(0).getFirstName());
}
}
package com.pluralsight.model;
public class Speaker {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
package com.pluralsight.repository;
import com.pluralsight.model.Speaker;
import java.util.ArrayList;
import java.util.List;
public class HibernateSpeakerRepositoryImpl implements SpeakerRepository {
public List<Speaker> findAll() {
List<Speaker> speakers = new ArrayList<Speaker>();
Speaker speaker = new Speaker();
speaker.setFirstName("Bryan");
speaker.setLastName("Hansen");
speakers.add(speaker);
return speakers;
}
}
package com.pluralsight.repository;
import com.pluralsight.model.Speaker;
import java.util.List;
public interface SpeakerRepository {
List<Speaker> findAll();
}
package com.pluralsight.service;
import com.pluralsight.model.Speaker;
import java.util.List;
public interface SpeakerService {
List<Speaker> findAll();
}
package com.pluralsight.service;
import com.pluralsight.model.Speaker;
import com.pluralsight.repository.HibernateSpeakerRepositoryImpl;
import com.pluralsight.repository.SpeakerRepository;
import java.util.List;
public class SpeakerServiceImpl implements SpeakerService {
private SpeakerRepository repository = new HibernateSpeakerRepositoryImpl();
public List<Speaker> findAll() {
return repository.findAll();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pluralsight</groupId>
<artifactId>conference-java</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
import com.pluralsight.repository.HibernateSpeakerRepositoryImpl;
import com.pluralsight.repository.SpeakerRepository;
import com.pluralsight.service.SpeakerService;
import com.pluralsight.service.SpeakerServiceImpl;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
@Configuration
@ComponentScan({"com.pluralsight"})
public class AppConfig {
/*
@Bean(name = "speakerService")
@Scope(value= BeanDefinition.SCOPE_SINGLETON)
public SpeakerService getSpeakerService() {
//SpeakerServiceImpl service = new SpeakerServiceImpl(getSpeakerRepository());
SpeakerServiceImpl service = new SpeakerServiceImpl();
//service.setRepository(getSpeakerRepository());
return service;
}
@Bean(name = "speakerRepository")
public SpeakerRepository getSpeakerRepository() {
return new HibernateSpeakerRepositoryImpl();
}*/
}
import com.pluralsight.service.SpeakerService;
import com.pluralsight.service.SpeakerServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Application {
public static void main(String args[]) {
ApplicationContext appContext = new AnnotationConfigApplicationContext(AppConfig.class);
//SpeakerService service = new SpeakerServiceImpl();
SpeakerService service = appContext.getBean("speakerService", SpeakerService.class);
System.out.println(service);
System.out.println(service.findAll().get(0).getFirstName());
SpeakerService service2 = appContext.getBean("speakerService", SpeakerService.class);
System.out.println(service2);
}
}
package com.pluralsight.model;
public class Speaker {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
conference-xml @ 86685349
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
conference @ 86685349
This diff is collapsed.
conference-java @ 86685349
This diff is collapsed.
conference-xml @ 86685349
This diff is collapsed.
This diff is collapsed.
conference-xml @ 86685349
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment