java使用@Component而不是声明性声明?
我用声明式的方式来制作spring管理的bean。它很好用。我现在打算走注释道。 我跟着这个Tutorial
我所做的是
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="com" />
</beans>
并使用组件注释
@Component
public class EmployeeServiceImpl implements EmployeeService {}
但当我启动我的web应用程序时,我会发现以下错误
java.lang.ClassNotFoundException: javax.annotation.Nullable
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)But when is start my web application i get below error
更新:-我在谷歌上发现了javax。注释。可在jsr305-1.3.7中找到Nullable。罐子但我认为jsr305-1.3.7的缺失。jar不是问题,因为我可以在没有jsr305-1.3.7的情况下在简单的spring hello world项目中实现它。罐子所以我认为问题出在其他地方
# 1 楼答案
将
jsr305-1.3.7.jar
添加到类路径。由于JVM
无法找到所需的类,因此您将获得异常