Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Fixed BeanPostProcessor detection. #9

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.scala.beans.factory.function;

import org.springframework.beans.factory.config.BeanPostProcessor;
import scala.Function0;

/**
Expand All @@ -37,4 +38,8 @@ public static <T> T apply(Function0<T> function) {
return function.apply();
}

public static BeanPostProcessor applyAsBeanPostProcessor(Function0<BeanPostProcessor> function) {
return function.apply();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@
package org.springframework.scala.beans.factory.function

import org.springframework.beans.factory.support.GenericBeanDefinition
import org.springframework.beans.factory.config.BeanPostProcessor

/**
* Default implementation of
* [[org.springframework.scala.beans.factory.function.FunctionalBeanDefinition]].
*
* @author Arjen Poutsma
*/
class FunctionalGenericBeanDefinition[T](beanFunction: () => T)
class FunctionalGenericBeanDefinition[T](beanFunction: () => T)(implicit manifest: Manifest[T])
extends GenericBeanDefinition with FunctionalBeanDefinition[T] {

setBeanClass(classOf[Function0Wrapper])
getConstructorArgumentValues.addIndexedArgumentValue(0, beanFunction)
setFactoryMethodName("apply")
val isBeanPostProcessor = classOf[BeanPostProcessor].isAssignableFrom(manifest.runtimeClass)
val factoryMethodName = if(isBeanPostProcessor) "applyAsBeanPostProcessor" else "apply"
setFactoryMethodName(factoryMethodName)

def beanCreationFunction = beanFunction
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ trait FunctionalConfiguration extends DelayedInit {

val beanType = manifest.runtimeClass.asInstanceOf[Class[T]]

val fbd = new FunctionalGenericBeanDefinition(beanFunction)
val fbd = new FunctionalGenericBeanDefinition(beanFunction)(manifest)
fbd.setScope(scope)
fbd.setLazyInit(lazyInit)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2011-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.scala.beans.factory.function

import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.springframework.scala.context.function.{FunctionalConfigApplicationContext, FunctionalConfiguration}
import org.springframework.beans.factory.annotation.{AutowiredAnnotationBeanPostProcessor, Autowired}
import org.scalatest.matchers.ShouldMatchers

@RunWith(classOf[JUnitRunner])
class BeanPostProcessorTests extends FunSuite with ShouldMatchers {

val applicationContext = new FunctionalConfigApplicationContext(classOf[ConfigWithBeanPostProcessor])

test("BeanPostProcessor support") {
applicationContext.getBean(classOf[AutowireSubject]).autowiredMember should not be (null)
}

}

class ConfigWithBeanPostProcessor extends FunctionalConfiguration {

bean()(new AutowiredAnnotationBeanPostProcessor)

bean()("autowireMe")

bean()(new AutowireSubject)

}

class AutowireSubject {

@Autowired
var autowiredMember : String = _

}