Aspect Class:
#Aspect
public class LoggingAspect {
#Before("e1() && e2()")
public void loggingAdvice(){
System.out.println("before execution of the method");
}
#Pointcut("execution(public String com.spring.Employee.getName())")
public void e1(){}
#Pointcut("execution(public String com.spring.Department.getName())")
public void e2(){}
}
Client Class:
public class AspectClient {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
Employee emp = (Employee) context.getBean("employee");
System.out.println(emp.getEmpId());
System.out.println(emp.getName());
System.out.println(emp.getDepartment().getName());
}
**Config 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" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<bean id= "employee" class="com.spring.Employee" autowire="byName">
<property name="empId" value="7329" />
<property name="name" value="Sagar" />
</bean>
<bean id= "department" class="com.spring.Department" >
<property name="name" value="ApplicationManagement" />
<property name="typeOfProjects" value="Maintenance" />
</bean>
<bean class="com.spring.LoggingAspect"/>
<aop:aspectj-autoproxy />
<context:annotation-config />
</beans>
Explanation:
#Before("e1() && e2()")
When I just call either e1() or e2() individually, it works but not both at same time.
I dont get any errors., Just the advices are not called.
I am using spring 3.2.3
AspectJ and AOP alliance jar files
Which is as expected. The pointcut never matches it will never match both the execution e1 and execution e2 on the same time. Instead of && you probably want || .
It basically is an if statement and both sides have to resolve to true a
Related
I am trying to create a Simple REST service that stores data in the db. This is a sample architecture going from REST controller to a MVC-Controller, which instantiates an Entity and tries to store it in the db via an autowired Repository.
The REST service is correctly invoked and replies what it has to; however, storing the entity fails and the autowired repository is null.
Can somebody help?
My REST service:
#RestController
#RequestMapping("/coord")
public class CoordService {
#RequestMapping(value = "/{name}", method = RequestMethod.GET)
public String getMuseo(#PathVariable String name) {
String result = "Hello " + name + ", I am saving on the db.";
new CoordController().saveCoord();
return result;
}
}
My application business logic (controller in MVC):
#Component
public class CoordController {
#Autowired
private CoordRepository coordRepository;
public void saveCoord() {
System.out.println("Ok controller");
Coord cg = new Coord();
System.out.println("Ok new");
cg.setCoord("xyz");
cg.setId(1L);
if (coordRepository == null) {
System.out.println("REP NULL!");
} else
coordRepository.save(cg);
System.out.println("Ok save()");
}
}
My Entity:
#Entity
#Configurable
public class Coord extends IdentifiableEntity {
#NotNull
private String coord;
public String getCoord() {
return this.coord;
}
public void setCoord(String coord) {
this.coord = coord;
}
}
My Repository:
#Repository
public interface CoordRepository extends
JpaSpecificationExecutor<Coord>,
JpaRepository<Coord, Long> {
}
My applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<context:property-placeholder location="classpath*:spring/*.properties" />
<context:component-scan base-package="com.lh.clte" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${database.driverClassName}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
<property name="initialSize" value="3" />
<property name="maxActive" value="10" />
</bean>
<tx:annotation-driven mode="proxy"
transaction-manager="transactionManager" />
<bean class="org.springframework.orm.jpa.JpaTransactionManager"
id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
id="entityManagerFactory">
<property name="persistenceUnitName" value="persistenceUnit" />
<property name="dataSource" ref="dataSource" />
</bean>
<jpa:repositories base-package="com.lh.clte.repository" />
</beans>
My persistence.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="persistenceUnit"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
<property name="hibernate.connection.charSet" value="UTF-8" />
</properties>
</persistence-unit>
</persistence>
Your problem is here
new CoordController().saveCoord();
You need to autowire your CoordController into your CoordService. By using new CoordController(), you are creating an instance of CoordController not managed by spring so its fields are not autowired.
#RestController
#RequestMapping("/coord")
public class CoordService {
#Autowired
private CoordController coordController;
#RequestMapping(value = "/{name}", method = RequestMethod.GET)
public String getMuseo(#PathVariable String name) {
String result = "Hello " + name + ", I am saving on the db.";
coordController.saveCoord();
return result;
}
}
By the way, your CoordService class should be named CoordController since its a controller (it has the #RestController annotation!) and your CoordController should be CoordService since it contains business logic.
After much hassle I'm here for help. I am not able to persist data to development database (and also Embedded database) from a test case. When I run the test case without asserting it passes without any exception. I using Spring Roo generated entities. With the same application context configuration I'm able to save data to the database from Spring controller. So I'm convinced that I don't have any problem with my entities.
#TransactionConfiguration(defaultRollback=false)
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration({ "/META-INF/spring/applicationContext.xml" })
#Transactional
public class UserServiceTest {
#Rollback(false)
#Test
public void test() {
Role role = new Role();
role.setRolename("ROLE_ADMIN");
// No Exception here on trying to persist
role.persist();
// Getting Exception here.. "No transaction is in progress"
// role.flush();
// Getting "No entity found for query exception"
assertEquals(Role.findRolesByRolenameEquals("ROLE_ADMIN").getSingleResult().getRolename(), "ROLE_ADMIN");
}
}
My applicationContext.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
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
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
">
<context:property-placeholder location="classpath*:META-INF/spring/*.properties" />
<context:spring-configured />
<context:component-scan base-package="com.company">
<context:exclude-filter expression=".*_Roo_.*"
type="regex" />
<context:exclude-filter expression="org.springframework.stereotype.Controller"
type="annotation" />
</context:component-scan>
<bean class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" id="dataSource">
<property name="driverClassName" value="${testDatabase.driverClassName}" />
<property name="url" value="${testDatabase.url}" />
<property name="username" value="${testDatabase.username}" />
<property name="password" value="${testDatabase.password}" />
<property name="testOnBorrow" value="true" />
<property name="testOnReturn" value="true" />
<property name="testWhileIdle" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="1800000" />
<property name="numTestsPerEvictionRun" value="3" />
<property name="minEvictableIdleTimeMillis" value="1800000" />
<property name="validationQuery" value="select 1 from INFORMATION_SCHEMA.TABLES" />
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager"
id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven mode="aspectj"
transaction-manager="transactionManager" proxy-target-class="true" />
<bean
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
id="entityManagerFactory">
<property name="persistenceUnitName" value="persistenceUnitTest" />
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
My Persistence.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="persistenceUnitTest"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.company.domain.User</class>
<class>com.company.domain.Role</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.hbm2ddl.auto" value="none" />
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.DefaultNamingStrategy" />
<property name="hibernate.connection.charSet" value="UTF-8" />
</properties>
</persistence-unit>
</persistence>
EDIT: Added Persistence logic
My Persistence logic in Role_Roo_Jpa_ActiveRecord.aj
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
// You may push code into the target .java compilation unit if you wish to edit any member(s).
package com.company.domain;
import com.company.domain.Role;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.transaction.annotation.Transactional;
privileged aspect Role_Roo_Jpa_ActiveRecord {
#PersistenceContext
transient EntityManager Role.entityManager;
public static final EntityManager Role.entityManager() {
EntityManager em = new Role().entityManager;
if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
return em;
}
public static long Role.countRoles() {
return entityManager().createQuery("SELECT COUNT(o) FROM Role o", Long.class).getSingleResult();
}
public static List<Role> Role.findAllRoles() {
return entityManager().createQuery("SELECT o FROM Role o", Role.class).getResultList();
}
public static Role Role.findRole(Integer roleId) {
if (roleId == null) return null;
return entityManager().find(Role.class, roleId);
}
public static List<Role> Role.findRoleEntries(int firstResult, int maxResults) {
return entityManager().createQuery("SELECT o FROM Role o", Role.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
}
#Transactional
public void Role.persist() {
if (this.entityManager == null) this.entityManager = entityManager();
this.entityManager.persist(this);
}
#Transactional
public void Role.remove() {
if (this.entityManager == null) this.entityManager = entityManager();
if (this.entityManager.contains(this)) {
this.entityManager.remove(this);
} else {
Role attached = Role.findRole(this.roleId);
this.entityManager.remove(attached);
}
}
#Transactional
public void Role.flush() {
if (this.entityManager == null) this.entityManager = entityManager();
this.entityManager.flush();
}
#Transactional
public void Role.clear() {
if (this.entityManager == null) this.entityManager = entityManager();
this.entityManager.clear();
}
#Transactional
public Role Role.merge() {
if (this.entityManager == null) this.entityManager = entityManager();
Role merged = this.entityManager.merge(this);
this.entityManager.flush();
return merged;
}
}
I tried both MySql and Hsqldb database with the same code. But no luck.
I also have another problem. In case of development I didn't have to specify Role and User classes in persistence.xml. If I don't specify them in test configuration I'm getting exceptions.
Roo lets you to configure the persistence engine as many times as you need, try to reconfigure your persistence settings from Roo shell using persistence setup command
In your applicationContext.xml you specified the context:component-scan base-package to com.campus but your entities are on com.company.domain.
Have you changed the main package after the web mvc command?
Try to set applicationContext.xml like this:
<context:component-scan base-package="com.company">
<context:exclude-filter expression=".*_Roo_.*"
type="regex" />
<context:exclude-filter expression="org.springframework.stereotype.Controller"
type="annotation" />
</context:component-scan>
Afther that, I think you can remove the class tags from persistencie.xml.
You need the flush in there. The insert statement doesn't get executed until flush is called.
And the findRolesByRolenameEquals method cannot read the object you have saved from the hibernate session as it uses a query to load the object
If you comment out the assert, and let the test finish, you should be able to see the record in the db as flush should occur when the transaction is complete, is that not the case?
I got it working by removing component-scan from my applicationContext.xml. Now I'm able to persist data into the database(both MySql and Hsqldb) from the test case. Now the test case is passing and the data is seen in the database.
<context:component-scan base-package="com.company">
<context:exclude-filter expression=".*_Roo_.*"
type="regex" />
<context:exclude-filter expression="org.springframework.stereotype.Controller"
type="annotation" />
</context:component-scan>
I still could not make out why this solved my problem. I am still finding a valid explanation here.
My other problem is still there. I had to manually put Role and User classes in persistence.xml.
I want to support rollback when an exception occurs in my code.
I use junit + datasource in Spring config file for testing and Glassfish 2.1 for the real code (using jndi datasource).
Here a sample of the code.
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = { "classpath:test-web-spring-config.xml" })
public class PersistTest {
#Autowired
Transformer transformer;
#Before
public void setUp() throws Exception {
}
#After
public void tearDown() throws Exception {
}
#Test
#Transactional("transactionManagerTest")
//#Rollback(false)
// #Ignore
public void test() {
transformer.export();
}
}
#Component
public class Transformer {
#Autowired
ContextPersist context;
#Transactional(propagation=Propagation.REQUIRED, rollbackFor=Exception.class)
public void export(){
//code here
// persist here
context.persist();
// to test a rollback
throw new RuntimeException("testing rollback2");
}
}
#Component
public class ContextPersist {
#Autowired
#Qualifier(value = "dataSource")
DataSource dataSource;
// bulk insert
JdbcTemplate jdbcTemplate;
#Transactional(propagation=Propagation.REQUIRED, rollbackFor=Exception.class)
public void persist() {
jdbcTemplate = new JdbcTemplate(dataSource);
//.. here I insert data with jdbcTemplate.batchUpdate(....)
// to test a rollback
throw new RuntimeException("testing rollback1");
}
}
That code doesn't rollback.
If I use #Rollback(true) in my Junit, the transaction will rollback. But I need the same behavior outside a JUnit.
EDITED : (added the spring config)
My project contains a webapp (demo.war) and a jar for DAO+businessrules
In my webapp, I have my transformer.
I have a parent Spring config in this webapp, and a common spring config shared with others webapps.
Here the files.
demo.war
web-spring-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<context:component-scan base-package="com.test" />
<tx:annotation-driven />
<task:annotation-driven/>
<import resource="classpath:common-spring-config.xml" />
</beans>
DAO.jar
common-spring-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<context:component-scan base-package="com.test" />
<tx:annotation-driven />
<task:annotation-driven/>
<!-- Hibernate -->
<bean id="hibernateSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="demo.datasource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean>
<!-- datasource -->
<bean id="demo.datasource" class="org.springframework.jndi.JndiObjectFactoryBean"
lazy-init="true">
<property name="jndiName" value="jdbc/demo" />
</bean>
</beans>
your transaction manager is
org.springframework.orm.hibernate3.HibernateTransactionManager
but you use JdbcTemplate
the AOP is configured to auto begin/commit/rollback on hibernate operations.
jdbcTemplate would not participate in any transaction.
no transaction = no rollback.
its like connection.setAutoCommit(true);
Recently I've been playing with Spring Data for Neo4j (version 2.1.0.BUILD-SNAPSHOT) and I'm having an issue related to its GraphRepository interface.
You can write a method that will search for a node of T class using the properties contained in the method's name, like this:
public interface UserRepository extends GraphRepository<User> {
public User findByUsername(String username);
public User findById(Long id);
}
My User class:
#NodeEntity
public class User {
#GraphId
Long id;
#Indexed
private String username;
private String password;
...
}
And my applicationContext.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/neo4j
http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:spring-configured />
<context:annotation-config />
<context:component-scan base-package="package.for.services" />
<neo4j:repositories base-package="package.for.repositories" />
<neo4j:config graphDatabaseService="graphDatabaseService" />
<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase"
destroy-method="shutdown" scope="singleton">
<constructor-arg value="/path/to/neo4j.db" />
<constructor-arg>
<map>
<entry key="allow_store_upgrade" value="true" />
</map>
</constructor-arg>
</bean>
</beans>
My issue is that findById(Long id) method does return a node with that specific id, but findByUsername(String username) does return null instead of a node with that specific username.
Any help will be appreciated.
Solved by recreating the database. Deleted its directory and launched the application again.
I guess the indexes have not been created correctly since the beggining, and Spring Data is not able to change them once they were already created.
Thank you.
Could I use SpEL inside the id attribute of a bean ?
e.g :
<bean id="#{T(com.om.m).PublicStaticFinalStringProperty}"...
This way it's not working, what should I change or it's not possible ?
Weird but possible (sample uses spring 3.1). Different versions working:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
">
<context:property-placeholder properties-ref="myProps"/>
<util:properties id="myProps" >
<prop key="x.y.z">possible</prop>
</util:properties>
<bean id="testBean" class="Bean">
<property name="value" value="weird"/>
</bean>
<bean id="${x.y.z}" class="Bean">
<property name="value" value="but"/>
</bean>
<bean id="#{testBean.value}" class="Bean">
<property name="value" value="${x.y.z}"/>
</bean>
</beans>
Bean.java
public class Bean implements InitializingBean {
String value;
public void setValue(String value) {
this.value = value;
}
public void afterPropertiesSet() throws Exception {
System.out.println(value);
}
}