1. download the zip, unzip it into some folder, let's say C:\Applications\apache-maven-3.0.3
2. setting up variables
M2_HOME=C:\Applications\apache-maven-3.0.3
put %M2_HOME% into PATH
M2_REPO=C:\Users\Paul\.m2\repository
3. mvn -v should work now.
4. to make sure a project maven compatible, use mvn eclipse:eclipse
5. in Eclipse, you need setup M2_REPO variable
select Window > Preferences. Select the Java > Build Path > Classpath Variables page.
Inject Non-Spring Bean
Additional Jar files:
org.springframework.aspects-3.1.0.M1.jar
c:\aspectj-1.6.11\lib\aspectjweaver.jar
Also need make sure JVM AspectJ-enabled.
put -javaagent:C:/aspectj-1.6.11/lib/aspectjweaver.jar
into VM Argument section
The above are just setting environments.
Why/when we want to inject stuff into a non-spring bean?
There are many scenarios that a bean is not instantiated by Spring, but we still want to inject value/references into this bean.
In config:
xmlns:aop="http://www.springframework.org/schema/aop"
...
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
...
<aop:spring-configured/>
<bean id='noSpringBean' class="packageA.NoSpringBean" abstract="true">
<property name="beanName" value="Bolun"/>
<property name="height" value="187"/>
</bean>
NoSpringBean.java
@Configurable("noSpringBean")
public class NoSpringBean
{
...
}
When you test it, you will see a lot of Waving stuff before our codes are really executed, performance wise, this could be really bad.
Adding org.springframework.transaction-3.1.0.M1.jar into path, removed a lot of complains.
org.springframework.aspects-3.1.0.M1.jar
c:\aspectj-1.6.11\lib\aspectjweaver.jar
Also need make sure JVM AspectJ-enabled.
put -javaagent:C:/aspectj-1.6.11/lib/aspectjweaver.jar
into VM Argument section
The above are just setting environments.
Why/when we want to inject stuff into a non-spring bean?
There are many scenarios that a bean is not instantiated by Spring, but we still want to inject value/references into this bean.
In config:
xmlns:aop="http://www.springframework.org/schema/aop"
...
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
...
<aop:spring-configured/>
<bean id='noSpringBean' class="packageA.NoSpringBean" abstract="true">
<property name="beanName" value="Bolun"/>
<property name="height" value="187"/>
</bean>
NoSpringBean.java
@Configurable("noSpringBean")
public class NoSpringBean
{
...
}
When you test it, you will see a lot of Waving stuff before our codes are really executed, performance wise, this could be really bad.
Adding org.springframework.transaction-3.1.0.M1.jar into path, removed a lot of complains.
Spring Example: Wired Together
package packageA;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class HelloApp2
{
public static void main(String[] args)
{
ApplicationContext ctx = new ClassPathXmlApplicationContext("config.xml");
GreetingService greetingService = (GreetingService) ctx.getBean("greetingService");
greetingService.sayALotOfGreeting();
greetingService.theWinnderOfOscar();
greetingService.sayGreeting();
Lime iLime = (Lime) ctx.getBean("lime");
iLime.drink();
}
}
Spring Example: Groovy File
class Lime implements packageA.Lime
{
void drink()
{
print "Groovy not in line!"
}
}
Labels:
Groovy
Spring Example: Injected Method Implementation
package packageA;
import java.lang.reflect.Method;
import org.springframework.beans.factory.support.MethodReplacer;
public class WinnerInEnvelop implements MethodReplacer
{
public Object reimplement(Object arg0, Method arg1, Object[] arg2) throws Throwable
{
System.out.println("Samuel Bolun Liu");
return null;
}
}
Labels:
Spring
Groovy in Spring
Now I could inject Groovy class into Spring, but the problem is Groovy class has to implement a Java interface, in this way, I could get the bean from application context.
I am wondering is it possible that I could get Groovy class without using interface?
I am wondering is it possible that I could get Groovy class without using interface?
Subscribe to:
Posts (Atom)