bean work

This commit is contained in:
eugenp 2013-05-25 01:10:44 +03:00
parent 94f9a60da1
commit 343a743229
7 changed files with 22 additions and 13 deletions

View File

@ -7,7 +7,6 @@ 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;
@ -18,7 +17,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" })

View File

@ -1,5 +1,7 @@
package org.baeldung.spring.config;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@ -10,10 +12,11 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@ComponentScan("org.baeldung.web")
public class WebConfig extends WebMvcConfigurerAdapter {
@Autowired
BeanFactory beanFactory;
public WebConfig() {
super();
}
}

View File

@ -1,16 +1,14 @@
package org.baeldung.web;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@Component
@Transactional
public class BeanA {
private IBeanC dependency;
public BeanA() {
super();
}
//
}

View File

@ -1,9 +1,15 @@
package org.baeldung.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@Component
public class BeanB implements IBeanB {
@Transactional
public class BeanB {
@Autowired
private BeanA beanA;
public BeanB() {
super();

View File

@ -3,7 +3,7 @@ package org.baeldung.web;
import org.springframework.stereotype.Component;
@Component
public class BeanC2 implements IBeanB {
public class BeanC2 implements IBeanC {
public BeanC2() {
super();

View File

@ -0,0 +1,5 @@
package org.baeldung.web;
public interface IBeanA {
//
}

View File

@ -4,8 +4,6 @@
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<bean id="beanA" class="org.baeldung.web.BeanA">
<property name="beanC" ref="beanC" />
</bean>
<!-- <bean id="beanA" abstract="true" class="org.baeldung.web.BeanA" /> -->
</beans>