Commit e1df448f authored by vivaddadhi's avatar vivaddadhi

Videos 1 and 2

parent c5dca5da
File added
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="com.pluralsight.conference-xml" />
<module name="com.pluralsight" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?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>org.example</groupId>
<artifactId>com.pluralsight</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.13.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>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
import com.pluralsight.repository.HibernateSpeakerRepositryImpl;
import com.pluralsight.repository.SpeakerRepository;
import com.pluralsight.service.SpeakerService;
import com.pluralsight.service.SpeakerServicesImpl;
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() {
// //SpeakerServicesImpl service = new SpeakerServicesImpl(getSpeakerRepository());
// SpeakerServicesImpl service = new SpeakerServicesImpl();
// //service.setRepository(getSpeakerRepository());
// return service;
// }
// @Bean(name = "speakerRepository")
// public SpeakerRepository getSpeakerRepository() {
// return new HibernateSpeakerRepositryImpl();
// }
}
import com.pluralsight.model.Speaker;
import com.pluralsight.service.SpeakerService;
import com.pluralsight.service.SpeakerServicesImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Application {
public static void main(String[] args) {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class);
//SpeakerService service = new SpeakerServicesImpl();
SpeakerService service = applicationContext.getBean("speakerService", SpeakerService.class);
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 org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
@Repository("speakerRepository")
public class HibernateSpeakerRepositryImpl 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.SpeakerRepository;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("speakerService")
public class SpeakerServicesImpl implements SpeakerService {
private SpeakerRepository repository;
public void setSpeakerRepository(SpeakerRepository repository) {
this.repository = repository;
}
public List<Speaker> findAll() {
return repository.findAll();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean name="speakerRepository"
class="com.pluralsight.repository.HibernateSpeakerRepositoryImpl" />
<bean name="speakerService" class="com.pluralsight.service.SpeakerServiceImpl" autowire="byType">
<!--<constructor-arg index="0" ref="speakerRepository" />-->
</bean>
</beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean name="speakerRepository"
class="com.pluralsight.repository.HibernateSpeakerRepositoryImpl" />
<bean name="speakerService" class="com.pluralsight.service.SpeakerServiceImpl" autowire="byType">
<!--<constructor-arg index="0" ref="speakerRepository" />-->
</bean>
</beans>
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="com.pluralsight" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?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>org.example</groupId>
<artifactId>com.pluralsight</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.13.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>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
import com.pluralsight.repository.HibernateSpeakerRepositryImpl;
import com.pluralsight.repository.SpeakerRepository;
import com.pluralsight.service.SpeakerService;
import com.pluralsight.service.SpeakerServicesImpl;
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() {
// //SpeakerServicesImpl service = new SpeakerServicesImpl(getSpeakerRepository());
// SpeakerServicesImpl service = new SpeakerServicesImpl();
// //service.setRepository(getSpeakerRepository());
// return service;
// }
// @Bean(name = "speakerRepository")
// public SpeakerRepository getSpeakerRepository() {
// return new HibernateSpeakerRepositryImpl();
// }
}
import com.pluralsight.model.Speaker;
import com.pluralsight.service.SpeakerService;
import com.pluralsight.service.SpeakerServicesImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Application {
public static void main(String[] args) {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class);
//SpeakerService service = new SpeakerServicesImpl();
SpeakerService service = applicationContext.getBean("speakerService", SpeakerService.class);
System.out.println(service);
System.out.println(service.findAll().get(0).getFirstName());
SpeakerService service2 = applicationContext.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 HibernateSpeakerRepositryImpl 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.HibernateSpeakerRepositryImpl;
import com.pluralsight.repository.SpeakerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("speakerService")
public class SpeakerServicesImpl implements SpeakerService {
private SpeakerRepository repository;
public SpeakerServicesImpl() {
System.out.println("SpeakerServiceImpl no args constructor");
}
public SpeakerServicesImpl (SpeakerRepository speakerRepository) {
System.out.println("SpeakerServiceImpl Repo constructor");
repository = speakerRepository;
}
@Autowired
public void setRepository(SpeakerRepository repository) {
System.out.println("SpeakerServiceImpl setter");
this.repository = repository;
}
public List<Speaker> findAll() {
return repository.findAll();
}
}
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