简体   繁体   English

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

[英]Using @Component instead of declarative declaration?

i was using declarative way to make beans the spring managed.It works fine. 我正在使用声明性的方式来使Spring管理bean。 I am planning to go annotattion way now. 我打算现在使用注释方式。 I followed this Tutorial 我遵循了本教程

What i did is 我所做的是

<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>

And used the Component annotation 并使用了Component注释

@Component
public class EmployeeServiceImpl implements EmployeeService {}

But when i start my web application i get below error 但是,当我启动我的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

UPDATE:- On google i found out that javax.annotation.Nullable can be found under jsr305-1.3.7.jar. 更新:-在谷歌上我发现javax.annotation.Nullable可以在jsr305-1.3.7.jar下找到。 But i think absence of jsr305-1.3.7.jar is not a problem as i could make it work in simple spring hello world project without the presence of jsr305-1.3.7.jar.So i think problem lies somewhere else. 但是我认为缺少jsr305-1.3.7.jar并不是问题,因为我可以在没有jsr305-1.3.7.jar的情况下使其在简单的Spring hello world项目中工作,所以我认为问题出在其他地方。

Add jsr305-1.3.7.jar to your classpath. jsr305-1.3.7.jar添加到您的类路径中。 You are getting the exception since the JVM is not able to find the required class 由于JVM无法找到所需的类,因此您正在获取异常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM