web3jをspring-mvcで立ち上げようとしたらこんなのでた

Etherum Web3j coreを使おうとして spring-boot と spring-mvcをうまく混在させたくて
設定してましたが以下のようなエラーが出てました

Caused by: java.lang.IllegalStateException: No SpringApplication sources have been defined. Either override the configure method or add an @Configuration annotation
at org.springframework.util.Assert.state(Assert.java:73)
at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:127)
at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
at com.sharebaseinc.web.WebInitializer.onStartup(WebInitializer.java:13)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more

初期化クラスのWebInitializerを@SpringBootApplicationとして設定すると以下のようなエラーになり

Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/sharecoin-web]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
... 6 more
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.helpers.NOPLoggerFactory loaded from file:/home/kouichi/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/sharecoin-web/WEB-INF/lib/slf4j-api-1.7.25.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.helpers.NOPLoggerFactory
at org.springframework.util.Assert.instanceCheckFailed(Assert.java:637)
at org.springframework.util.Assert.isInstanceOf(Assert.java:537)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:274)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:98)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:230)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:209)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:69)
at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:292)
at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154)
at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134)
at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
at com.sharebaseinc.web.WebInitializer.onStartup(WebInitializer.java:13)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more

これをsl4jが依存複数しているみたいなので、web3jの設定から産sy等しているsprinbgootを外します。


org.web3j
web3j-spring-boot-starter
1.6.0


org.springframework.boot
spring-boot-starter-logging



そこからSpring-MVCの設定クラス*1と初期化クラス*2を以下を参考に書き換えます
書き換えると行っても、Annotationを記載するのと継承クラスを変えただけ。

https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html

  • WebMvcConfigurer

@Configuration
@EnableWebMvc
public class ShareBaseWebConfig implements WebMvcConfigurer

  • WebInitializer

public class WebInitializer implements WebApplicationInitializer {

とりあえず起動しました。
他のところでエラーになるかもしれないですが一旦ここまで

*1:ShareBaseWebConfig implements WebMvcConfigurer

*2:WebApplicationInitilizer