Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pluralsight-projects
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Deep Bhuller
pluralsight-projects
Commits
8f4c5995
Commit
8f4c5995
authored
Mar 31, 2021
by
dbhuller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
autowired beans at class level with steretype annotations
parent
7f21e077
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
6 deletions
+22
-6
AppConfig.java
...roject/conference-javaconfig/src/main/java/AppConfig.java
+9
-6
HibernateSpeakerRepositoryImpl.java
...om/example/repository/HibernateSpeakerRepositoryImpl.java
+2
-0
SpeakerServiceImpl.java
...src/main/java/com/example/service/SpeakerServiceImpl.java
+11
-0
AppConfig.class
...ject/conference-javaconfig/target/classes/AppConfig.class
+0
-0
HibernateSpeakerRepositoryImpl.class
...m/example/repository/HibernateSpeakerRepositoryImpl.class
+0
-0
SpeakerServiceImpl.class
...rget/classes/com/example/service/SpeakerServiceImpl.class
+0
-0
No files found.
springframework-springfundamentals-project/conference-javaconfig/src/main/java/AppConfig.java
View file @
8f4c5995
...
@@ -4,26 +4,29 @@ import com.example.service.SpeakerService;
...
@@ -4,26 +4,29 @@ import com.example.service.SpeakerService;
import
com.example.service.SpeakerServiceImpl
;
import
com.example.service.SpeakerServiceImpl
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Scope
;
import
org.springframework.context.annotation.Scope
;
@Configuration
@Configuration
@ComponentScan
({
"com.example"
})
public
class
AppConfig
{
public
class
AppConfig
{
/*
@Bean(name = "speakerService")
@Bean(name = "speakerService")
@Scope(value = BeanDefinition.SCOPE_SINGLETON)
@Scope(value = BeanDefinition.SCOPE_SINGLETON)
//
@Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
@Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
public SpeakerService getSpeakerService() {
public SpeakerService getSpeakerService() {
//
Using Constructor Injection
//
Using Constructor Injection
SpeakerServiceImpl service = new SpeakerServiceImpl(getSpeakerRespository());
SpeakerServiceImpl service = new SpeakerServiceImpl(getSpeakerRespository());
// config service with repository (setter injection)
//config service with repository (setter injection)
// service.setRepository(getSpeakerRespository());
service.setRepository(getSpeakerRespository());
SpeakerServiceImpl service = new SpeakerServiceImpl();
return service;
return service;
}
}
@Bean(name = "speakerRepository")
@Bean(name = "speakerRepository")
public SpeakerRepository getSpeakerRespository() {
public SpeakerRepository getSpeakerRespository() {
return new HibernateSpeakerRepositoryImpl();
return new HibernateSpeakerRepositoryImpl();
}
}
*/
}
}
springframework-springfundamentals-project/conference-javaconfig/src/main/java/com/example/repository/HibernateSpeakerRepositoryImpl.java
View file @
8f4c5995
package
com
.
example
.
repository
;
package
com
.
example
.
repository
;
import
com.example.model.Speaker
;
import
com.example.model.Speaker
;
import
org.springframework.stereotype.Repository
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
@Repository
(
"speakerRepository"
)
public
class
HibernateSpeakerRepositoryImpl
implements
SpeakerRepository
{
public
class
HibernateSpeakerRepositoryImpl
implements
SpeakerRepository
{
@Override
@Override
...
...
springframework-springfundamentals-project/conference-javaconfig/src/main/java/com/example/service/SpeakerServiceImpl.java
View file @
8f4c5995
...
@@ -3,14 +3,23 @@ package com.example.service;
...
@@ -3,14 +3,23 @@ package com.example.service;
import
com.example.model.Speaker
;
import
com.example.model.Speaker
;
import
com.example.repository.HibernateSpeakerRepositoryImpl
;
import
com.example.repository.HibernateSpeakerRepositoryImpl
;
import
com.example.repository.SpeakerRepository
;
import
com.example.repository.SpeakerRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.List
;
@Service
(
"speakerService"
)
public
class
SpeakerServiceImpl
implements
SpeakerService
{
public
class
SpeakerServiceImpl
implements
SpeakerService
{
private
SpeakerRepository
repository
;
private
SpeakerRepository
repository
;
public
SpeakerServiceImpl
()
{
System
.
out
.
println
(
"SpeakerServiceImpl no args Constructor"
);
}
public
SpeakerServiceImpl
(
SpeakerRepository
repository
)
{
public
SpeakerServiceImpl
(
SpeakerRepository
repository
)
{
System
.
out
.
println
(
"SpeakerServiceImpl repository Constructor"
);
this
.
repository
=
repository
;
this
.
repository
=
repository
;
}
}
...
@@ -19,7 +28,9 @@ public class SpeakerServiceImpl implements SpeakerService {
...
@@ -19,7 +28,9 @@ public class SpeakerServiceImpl implements SpeakerService {
return
repository
.
findAll
();
return
repository
.
findAll
();
}
}
@Autowired
public
void
setRepository
(
SpeakerRepository
repository
)
{
public
void
setRepository
(
SpeakerRepository
repository
)
{
System
.
out
.
println
(
"SpeakerServiceImpl repository setter"
);
this
.
repository
=
repository
;
this
.
repository
=
repository
;
}
}
}
}
springframework-springfundamentals-project/conference-javaconfig/target/classes/AppConfig.class
View file @
8f4c5995
No preview for this file type
springframework-springfundamentals-project/conference-javaconfig/target/classes/com/example/repository/HibernateSpeakerRepositoryImpl.class
View file @
8f4c5995
No preview for this file type
springframework-springfundamentals-project/conference-javaconfig/target/classes/com/example/service/SpeakerServiceImpl.class
View file @
8f4c5995
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment