私はGradleのによって管理されている複数の春ブーツmicroserviceのアプリを持っています。そのように整理共通jarファイルとドメイン固有のjarファイルがあります:
| common/
|-- common.jar
| p/
|-- p-ingest.jar
| g/
|-- g-ingest.jar
私の一般的なjarファイルは、クラスを持っているBaseRESTService
autowiresこと、HttpServletRequest
( -ではない私のコード私はすでに知っている悪い考えです)。共通のp-ingest.jar輸入、としてG-取り込み瓶を行います。geoallocは問題なく動作します。しかし、P-インジェスト、文字通りG-インジェストからコピーされた、実行されません。P-インジェストコンテキストの試みを初期化するとき、次の例外を取得します。
Field request in com.company.common.BaseRESTService required a bean of type 'javax.servlet.http.HttpServletRequest' that could not be found.
私は春に新しいものではない、と私は部品のスキャンとオートワイヤリングを理解し、すべてのことが、私は2日間これに取り組んできたと私は何が起こっているか理解することはできません。私は走ったgradle dependencies
両方のプロジェクトに、そして木は同じです。以下は、P-インジェストのブートアプリケーションクラスは次のとおりです。
@SpringBootApplication
@ComponentScan(
basePackageClasses = com.company.common.ConfigurationSearchCriteriaFactory.class,
basePackages = {"com.company.erd"})
@EnableJpaRepositories(basePackages = "com.company.erd")
@EntityScan(basePackages = {"com.company.erd"})
public class PortfolioRiskIngestApplication implements ApplicationRunner {
private static final Log logger = LogFactory.getLog(IngestApplication.class);
@Autowired
private IngestService ingestService;
public PIngestApplication(PIngestService ingestService) {this.ingestService = ingestService;}
public static void main(String[] args) {
SpringProfileHelper.setProfileFromAwsEnvironment();
SpringApplication app = new SpringApplication(PIngestApplication.class);
app.setWebEnvironment(false);
app.run(args);
}
@PostConstruct
void started() {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}
@Override
public void run(ApplicationArguments applicationArguments) {
// define the log info
LogInfo info = LogInfo.newInstance("run", new Object[] { StringUtility.arrayToString(applicationArguments.getSourceArgs()) });
// log entry
logger.info(info.entry());
ingestService.run(applicationArguments.getSourceArgs());
// log exit
logger.info(info.exit());
}
}
そして、ここからの抜粋ですBaseRestService
:
public class BaseRESTService
{
private static final Log logger = LogFactory.getLog(BaseRESTService.class);
@Autowired
private HttpServletRequest request;
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(value = EntityNotFoundException.class)
public ErrorResponse handleEntityNotFoundException(EntityNotFoundException e){
ErrorResponse errorResponse = new ErrorResponse();
errorResponse.setErrorCode(HttpStatus.NOT_FOUND.value());
errorResponse.setErrorMessage(e.getMessage());
logger.error(e.getMessage(), e);
return errorResponse;
}
特にない。関係するすべてのクラスは非常に簡単です。私は、誰もが私が間違ってやっているのと持っている任意のアイデアを歓迎します...
私は私の問題を考え出し、それは新人の間違いでした。怠惰のうち、私たちは私たちだけのRESTアプリケーションのために意図された共通瓶に持っていたコントローラを拾った私達の全体のコードベース、全体のコンポーネントスキャンをしました。コンポーネントのスキャンのみ実際の所望のパッケージが働いていました。