这是我的项目结构
父级是客户端、控制器、服务和存储库的父项目。
现在我想在controller中添加service的依赖关系,所以在controller pom.xml中添加了相同的内容
<dependency>
<groupId>com.freelancing.fullstack</groupId>
<artifactId>service</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
@RestController
public class MainController
{
@Autowired
ServiceClass sc;
@GetMapping("test")
public void testing()
{
sc.callService();
}
}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mainController' defined in file [E:\parent\controller\target\classes\org\controller\MainController.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.controller.MainController] from ClassLoader [org.springframework.boot.devtools.restart.classloader.RestartClassLoader@574aa597]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:572) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.controller.ControllerClass.main(ControllerClass.java:11) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.2.2.RELEASE.jar:2.2.2.RELEASE]
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.controller.MainController] from ClassLoader [org.springframework.boot.devtools.restart.classloader.RestartClassLoader@574aa597]
at org.springframework.util.ReflectionUtils.getDeclaredFields(ReflectionUtils.java:734) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.util.ReflectionUtils.doWithLocalFields(ReflectionUtils.java:666) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.buildResourceMetadata(CommonAnnotationBeanPostProcessor.java:382) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.findResourceMetadata(CommonAnnotationBeanPostProcessor.java:363) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:311) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1094) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:569) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
... 20 common frames omitted
Caused by: java.lang.NoClassDefFoundError: Lorg/service/ServiceClass;
at java.lang.Class.getDeclaredFields0(Native Method) ~[na:1.8.0_212]
at java.lang.Class.privateGetDeclaredFields(Class.java:2583) ~[na:1.8.0_212]
at java.lang.Class.getDeclaredFields(Class.java:1916) ~[na:1.8.0_212]
at org.springframework.util.ReflectionUtils.getDeclaredFields(ReflectionUtils.java:729) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
... 26 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.service.ServiceClass
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_212]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_212]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_212]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_212]
at org.springframework.boot.devtools.restart.classloader.RestartClassLoader.loadClass(RestartClassLoader.java:144) ~[spring-boot-devtools-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_212]
... 30 common frames omitted
seems like ServiceClass bean is not available at runtime.
添加componentscan注释后
facing this issue.
> [INFO] Scanning for projects... [INFO] [INFO] ----------------<
> com.freelancing.fullstack:controller >---------------- [INFO] Building
> controller 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar
> ]--------------------------------- [INFO] [INFO] >>>
> spring-boot-maven-plugin:2.2.2.RELEASE:run (default-cli) >
> test-compile @ controller >>> [INFO] [INFO] ---
> maven-resources-plugin:3.1.0:copy-resources (copy-resources) @
> controller --- [INFO] Using 'UTF-8' encoding to copy filtered
> resources. [INFO] Copying 22 resources [INFO] [INFO] ---
> maven-resources-plugin:3.1.0:resources (default-resources) @
> controller --- [INFO] Using 'UTF-8' encoding to copy filtered
> resources. [INFO] Copying 1 resource [INFO] Copying 0 resource [INFO]
> [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @
> controller --- [INFO] Nothing to compile - all classes are up to date
> [INFO] [INFO] --- maven-resources-plugin:3.1.0:testResources
> (default-testResources) @ controller --- [INFO] Using 'UTF-8' encoding
> to copy filtered resources. [INFO] skip non existing resourceDirectory
> E:\parent\controller\src\test\resources [INFO] [INFO] ---
> maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @
> controller --- [INFO] Nothing to compile - all classes are up to date
> [INFO] [INFO] <<< spring-boot-maven-plugin:2.2.2.RELEASE:run
> (default-cli) < test-compile @ controller <<< [INFO] [INFO] [INFO]
> --- spring-boot-maven-plugin:2.2.2.RELEASE:run (default-cli) @ controller --- [INFO] Attaching agents: []
>
> . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __
> _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / /
> =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.2.2.RELEASE)
>
> 2019-12-27 10:51:29.859 INFO 6184 --- [ restartedMain]
> org.controller.ControllerClass : Starting ControllerClass on
> DESKTOP-551C51M with PID 6184 (E:\parent\controller\target\classes
> started by sparsh in E:\parent\controller) 2019-12-27 10:51:29.864
> INFO 6184 --- [ restartedMain] org.controller.ControllerClass
> : No active profile set, falling back to default profiles: default
> 2019-12-27 10:51:29.927 INFO 6184 --- [ restartedMain]
> .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults
> active! Set 'spring.devtools.add-properties' to 'false' to disable
> 2019-12-27 10:51:29.927 INFO 6184 --- [ restartedMain]
> .e.DevToolsPropertyDefaultsPostProcessor : For additional web related
> logging consider setting the 'logging.level.web' property to 'DEBUG'
> 2019-12-27 10:51:31.375 INFO 6184 --- [ restartedMain]
> o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with
> port(s): 9091 (http) 2019-12-27 10:51:31.384 INFO 6184 --- [
> restartedMain] o.apache.catalina.core.StandardService : Starting
> service [Tomcat] 2019-12-27 10:51:31.384 INFO 6184 --- [
> restartedMain] org.apache.catalina.core.StandardEngine : Starting
> Servlet engine: [Apache Tomcat/9.0.29] 2019-12-27 10:51:31.456 INFO
> 6184 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] :
> Initializing Spring embedded WebApplicationContext 2019-12-27
> 10:51:31.457 INFO 6184 --- [ restartedMain]
> o.s.web.context.ContextLoader : Root WebApplicationContext:
> initialization completed in 1529 ms 2019-12-27 10:51:31.753 INFO 6184
> --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 2019-12-27
> 10:51:31.805 INFO 6184 --- [ restartedMain]
> o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class
> path resource [resources/index.html] 2019-12-27 10:51:31.944 WARN
> 6184 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer :
> Unable to start LiveReload server 2019-12-27 10:51:31.950 INFO 6184
> --- [ restartedMain] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator' 2019-12-27
> 10:51:32.009 INFO 6184 --- [ restartedMain]
> o.apache.catalina.core.StandardService : Stopping service [Tomcat]
> 2019-12-27 10:51:32.019 INFO 6184 --- [ restartedMain]
> ConditionEvaluationReportLoggingListener :
>
> Error starting ApplicationContext. To display the conditions report
> re-run your application with 'debug' enabled. 2019-12-27 10:51:32.027
> ERROR 6184 --- [ restartedMain]
> o.s.b.d.LoggingFailureAnalysisReporter :
>
> *************************** APPLICATION FAILED TO START
> ***************************
>
> Description:
>
> Web server failed to start. Port 9091 was already in use.
>
> Action:
>
> Identify and stop the process that's listening on port 9091 or
> configure this application to listen on another port.
>
> 2019-12-27 10:51:32.029 INFO 6184 --- [ restartedMain]
> o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down
> ExecutorService 'applicationTaskExecutor' [INFO]
> ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO]
> ------------------------------------------------------------------------ [INFO] Total time: 7.045 s [INFO] Finished at:
> 2019-12-27T10:51:32+05:30 [INFO]
> ------------------------------------------------------------------------
请帮忙
删除服务依赖关系中的作用域provided
。Maven依赖关系作用域provided
将在构建和测试项目期间使用。它们也需要运行,但不导出(因为期望依赖关系将由运行时提供,例如由servlet容器或应用程序服务器提供)。使用方法如下:
<dependency>
<groupId>com.freelancing.fullstack</groupId>
<artifactId>service</artifactId>
<version>${project.version}</version>
</dependency>
在springboot应用程序中,通常将基本包作为主应用程序所在的包级别。因为您有一个多模块的项目,所以可能没有扫描其他包来创建bean。因此,请尝试使用以下配置,例如,为自动配置的类路径扫描指定要spring的基本包:
@ComponentScan(basePackages = {"com.yourBasePackage"})
英文原文:http://emberjs.com/guides/models/connecting-to-an-http-server/ 如果Ember应用需要从HTTP服务器加载JSON数据,本指南将介绍如何配置Ember Data来从服务器端加载记录,不论服务器返回的数据格式是什么样子。 仓库使用了一个称为适配器,知道如何通过网络进行通信的对象。默认情况下,仓库会使用DS.RESTAdapter
我用Anaconda创建了一个虚拟环境。激活后,我可以启动python3 shell并导入keras库,我得到以下警告,但在其他情况下它似乎可以工作。 /home/ryan/anaconda3/envs/spyderudemy/lib/python3.6/site packages/h5py/init.py:36:FutureWarning:将issubdtype的第二个参数从转换为。将来,它将被
我正在尝试定义一个Java 9模块。我定义了类似的东西: 然后,我的许多文件开始给我错误,他们找不到一些包。然后我使用了IntelliJ的自动帮助功能,并将其添加到我的模块信息中。java中有几个“requires”语句。所以它变成了这样: 现在IntelliJ显示了我所有的代码,没有错误。但当我在“Maven项目”窗口中单击“编译”(我使用Maven 3.5.3和Oracle JDK 10进行编
问题内容: 我有一个ParseService,我想对其进行模拟以测试使用它的所有控制器,我一直在阅读有关茉莉花间谍的信息,但对我来说仍然不清楚。谁能给我一个关于如何模拟定制服务并在Controller测试中使用它的示例吗? 现在,我有一个使用服务插入书的控制器: 服务是这样的: 到目前为止,我的测试如下所示: 现在测试失败: 我做错了什么? 问题答案: 我做错的是没有在beforeEach中将模拟
我可以在Android emulator中做些什么来将其连接到我位于或? 我已经尝试过了,但是模拟器仍然像谷歌搜索一样接受我的请求localhost或者更糟的是,它说在我的网络服务器正常运行时没有找到这个页面。