使用@Component而不是声明性声明?

时间:2014-02-28 09:00:04

标签: java spring dependency-injection spring-annotations

我正在使用声明式的方式来使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 {}

但是,当我启动我的网络应用程序时,我得到以下错误

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.annotation.Nullable可以在jsr305-1.3.7.jar下找到。但我认为缺少jsr305-1.3.7.jar不是问题,因为我可以在没有jsr305-1.3.7.jar的情况下使它在简单的春天你好世界项目中工作。所以我认为问题出在其他地方。

1 个答案:

答案 0 :(得分:0)

jsr305-1.3.7.jar添加到您的类路径中。您收到异常,因为JVM无法找到所需的类