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