以下のようなスプリングレストアプリケーションがあり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 メソッドにヒットし、サービス Bean の deployTemplate オブジェクトも初期化されます。
ただし、この Bean は IngestorController に対して自動配線されません。postman から rest エンドポイントをヒットすると、サービス Bean の deployTemplate プロパティが null になっています。Controller の ingestorService 変数に割り当てられているオブジェクトは、init メソッドで呼び出されたオブジェクトとは別のオブジェクトです...
サービス Bean シングルトンを作成しようとしましたが (デフォルトのスコープがシングルトンであっても)、うまくいきません...
私がやっている間違いを見つけることができません..どんな提案もありがとう...