我有2个豆,一个是Singleton,另一个是原型
@Scope(value="singleton")
@Component
public class A{
@Autowired
B b;
}
另一个豆
@Scope(value="prototype")
@Component
public class B{
}
通过代码,我能够分别获得A和B的bean范围,
bean.getClass().getAnnotations(Scope.class)
如何获取已在A中自动连线的Bean B的范围。由于A是单例,因此当我尝试在A中获取B Bean的范围时,它也应该是单例。.
不确定如何通过代码获取该信息...
答案 0 :(得分:0)
您可以将BeanFactory用于BeanDefintion,它包含范围
Traceback (most recent call last):
File "C:\Users\Grace\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 1139, in _do_call
return fn(*args)
File "C:\Users\Grace\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 1121, in _run_fn
status, run_metadata)
File "C:\Users\Grace\Anaconda3\envs\tensorflow\lib\contextlib.py", line 66, in __exit__
next(self.gen)
File "C:\Users\Grace\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 466, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.OutOfRangeError: FIFOQueue '_2_model/Input/batch_1/fifo_queue' is closed and has insufficient elements (requested 1, current size 0)
[[Node: model/Input/batch_1 = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_UINT8, DT_FLOAT], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](model/Input/batch_1/fifo_queue, model/Input/batch_1/n)]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "predict_nick.py", line 584, in <module>
tf.app.run(main=main(args))
File "predict_nick.py", line 565, in main
train(args)
File "predict_nick.py", line 307, in train
model.tf_summary_train_loss])
File "C:\Users\Grace\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 789, in run
run_metadata_ptr)
File "C:\Users\Grace\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 997, in _run
feed_dict_string, options, run_metadata)
File "C:\Users\Grace\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 1132, in _do_run
target_list, options, run_metadata)
File "C:\Users\Grace\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 1152, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.OutOfRangeError: FIFOQueue '_2_model/Input/batch_1/fifo_queue' is closed and has insufficient elements (requested 1, current size 0)
[[Node: model/Input/batch_1 = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_UINT8, DT_FLOAT], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](model/Input/batch_1/fifo_queue, model/Input/batch_1/n)]]
Caused by op 'model/Input/batch_1', defined at:
File "predict_nick.py", line 584, in <module>
tf.app.run(main=main(args))
File "predict_nick.py", line 565, in main
train(args)
File "predict_nick.py", line 256, in train
model = Model(args, data)
File "C:\Users\Grace\Documents\FCRN-DepthPrediction\tensorflow\modules\framework.py", line 50, in __init__
self.build_model(data)
File "C:\Users\Grace\Documents\FCRN-DepthPrediction\tensorflow\modules\framework.py", line 64, in build_model
self.train = Train(self.args, data.tf_train_image_key, data.tf_train_image, data.tf_train_depth_key, data.tf_train_depth, self.input_size, self.output_size, data.datasetObj.max_depth, data.dataset_name, self.args.data_aug)
File "C:\Users\Grace\Documents\FCRN-DepthPrediction\tensorflow\modules\train.py", line 95, in __init__
tf_batch_image_resized, tf_batch_image_resized_uint8, tf_batch_depth_resized = tf.train.batch([self.tf_image_resized, self.tf_image_resized_uint8, self.tf_depth_resized], batch_size, num_threads, capacity, shapes=[input_size.getSize(), input_size.getSize(), output_size.getSize()])
File "C:\Users\Grace\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\training\input.py", line 919, in batch
name=name)
File "C:\Users\Grace\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\training\input.py", line 716, in _batch
dequeued = queue.dequeue_many(batch_size, name=name)
File "C:\Users\Grace\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\data_flow_ops.py", line 457, in dequeue_many
self._queue_ref, n=n, component_types=self._dtypes, name=name)
File "C:\Users\Grace\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\gen_data_flow_ops.py", line 946, in _queue_dequeue_many_v2
timeout_ms=timeout_ms, name=name)
File "C:\Users\Grace\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 767, in apply_op
op_def=op_def)
File "C:\Users\Grace\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 2506, in create_op
original_op=self._default_original_op, op_def=op_def)
File "C:\Users\Grace\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 1269, in __init__
self._traceback = _extract_stack()
OutOfRangeError (see above for traceback): FIFOQueue '_2_model/Input/batch_1/fifo_queue' is closed and has insufficient elements (requested 1, current size 0)
[[Node: model/Input/batch_1 = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_UINT8, DT_FLOAT], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](model/Input/batch_1/fifo_queue, model/Input/batch_1/n)]]
(getBeanFactory()在ConfigurableWebApplicationContext上定义,该接口是除StubWebApplicationContext之外的每个具体ApplicationContext都实现的接口)