我有一个弹簧休息应用程序,它有Rest Controller
如下
@RestController
public class IngestorController
{
@Autowired
private IngestorService ingestorService;
@RequestMapping( value = "/ingestor/createAndDeploy/{ingestorName}", method = RequestMethod.POST )
public void createAndDeploy( @PathVariable String ingestorName )
{
ingestorService.createAndDeploy( ingestorName );
}
}
同样,我有一个Service Bean
如下
@Service
public class IngestorService
{
@Autowired
private IngestorCommandBuilder ingestorCommandBuilder;
private String uri;
private DeployTemplate deployTemplate;
public void init() throws URISyntaxException
{
deployTemplate = new DeployTemplate( new URI( uri ) );
}
@Transactional
public void createAndDeploy( Ingestor ingestor )
{
//.....
}
}
我有Spring config
如下所示
<bean id="ingestorCommandBuilder" class="org.amaze.server.ingestor.IngestorCommandBuilder" />
<bean id="ingestorService" class="org.amaze.server.service.IngestorService" init-method="init">
<property name="uri" value="http://localhost:15217" />
</bean>
<bean id="ingestorController" class="org.amaze.server.controller.IngestorController"/>
每当我尝试启动应用程序上下文时,应用程序上下文就会启动,它会触发 IngestorService 中的 init 方法,deployTemplate 对象也会为服务 bean 初始化。
但是这个 bean 不是为 IngestorController 自动装配的。当我从邮递员点击其余端点时,服务 bean 的 deployTemplate 属性为 null。分配给 Controller 中的 ingestorService 变量的对象是另一个对象,而不是为 init 方法调用的对象...
我尝试将服务 bean 设为单例(即使默认范围是单例)但 dint 工作......
我无法找出我正在做的错误..任何建议表示赞赏...