bean work
This commit is contained in:
parent
f5990cb42b
commit
59bd37ec10
@ -7,6 +7,7 @@ import javax.sql.DataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
|
||||
@ -17,7 +18,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
// @Configuration
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
@PropertySource({ "classpath:persistence-mysql.properties" })
|
||||
@ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" })
|
||||
|
@ -1,5 +1,5 @@
|
||||
package org.baeldung.web;
|
||||
|
||||
public interface IBeanB {
|
||||
public interface IServiceB {
|
||||
//
|
||||
}
|
@ -6,12 +6,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class ServiceA implements IServiceA {
|
||||
public class ServiceA {
|
||||
|
||||
@Autowired
|
||||
private ServiceB serviceB;
|
||||
|
||||
public ServiceA() {
|
||||
public ServiceA(final IServiceB serviceB) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,11 @@
|
||||
package org.baeldung.web;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class ServiceB {
|
||||
|
||||
@Autowired
|
||||
private IServiceA serviceA;
|
||||
public class ServiceB implements IServiceB {
|
||||
|
||||
public ServiceB() {
|
||||
super();
|
||||
|
@ -3,18 +3,17 @@ package org.baeldung.web;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
// @Component
|
||||
public class Setup implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
private boolean setupDone;
|
||||
|
||||
@Autowired
|
||||
IServiceA serviceA;
|
||||
ServiceA serviceA;
|
||||
|
||||
@Autowired
|
||||
ServiceB serviceB;
|
||||
IServiceB serviceB;
|
||||
|
||||
public Setup() {
|
||||
super();
|
||||
@ -25,7 +24,8 @@ public class Setup implements ApplicationListener<ContextRefreshedEvent> {
|
||||
@Override
|
||||
public final void onApplicationEvent(final ContextRefreshedEvent event) {
|
||||
if (!setupDone) {
|
||||
//
|
||||
System.out.println();
|
||||
setupDone = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user