Spring 3.1没有xml,只是配置不起作用
所以我试图实现 Spring 3.1 博客文章中提到的关于 From XML to @Configuration,但它不想按预期工作。这是我正在使用的 web.xml(这是唯一的 xml),MvcFeatures 和 MvcBeans 或多或少与博客中的相同,只是添加了一些我的 bean。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
com.example.config.MvcFeatures
com.example.config.MvcBeans
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
</web-app>
当尝试启动这个东西时,我在控制台中收到这些消息:
21 Mar 2011 00:52:58,203 INFO org.springframework.web.context.support.AnnotationConfigWebApplicationContext []: No annotated classes found for specified class/package [com.example.config.MvcFeatures]
21 Mar 2011 00:52:58,203 INFO org.springframework.web.context.support.AnnotationConfigWebApplicationContext []: No annotated classes found for specified class/package [com.example.config.MvcBeans]
有什么想法可能是错误的吗?据我了解,我认为它不喜欢 contextConfigLocation 参数值。
编辑:添加 MvcFeatures 以防有帮助..
@FeatureConfiguration
public class MvcFeatures {
/**
* Enables the Spring MVC @Controller programming model.
*/
@Feature
public MvcAnnotationDriven annotationDriven(ConversionService conversionService) {
return new MvcAnnotationDriven().conversionService(conversionService)
.argumentResolvers(new CustomArgumentResolver());
}
/**
* Maps '/' requests to the 'home' view.
*/
@Feature
public MvcViewControllers viewController() {
return new MvcViewControllers("/", "index");
}
/**
* Enables Spring's component scanning feature.
*/
@Feature
public ComponentScanSpec componentScan() {
return new ComponentScanSpec("com.example.controllers").excludeFilters(
new AnnotationTypeFilter(Configuration.class), new AnnotationTypeFilter(
FeatureConfiguration.class));
}
}
So I'm trying to implement things mentioned in Spring's 3.1 blog post about From XML to @Configuration, but it doesn't want to work as supposed. Here is the web.xml (and that's the only xml) I'm using and the MvcFeatures and MvcBeans more or less are the same as in the blog just added few my beans.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
com.example.config.MvcFeatures
com.example.config.MvcBeans
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
</web-app>
When trying to launch this thing up I get these messages in console:
21 Mar 2011 00:52:58,203 INFO org.springframework.web.context.support.AnnotationConfigWebApplicationContext []: No annotated classes found for specified class/package [com.example.config.MvcFeatures]
21 Mar 2011 00:52:58,203 INFO org.springframework.web.context.support.AnnotationConfigWebApplicationContext []: No annotated classes found for specified class/package [com.example.config.MvcBeans]
Any ideas what could be wrong? From what I understand i think it doesn't like the contextConfigLocation param values.
EDIT: Adding the MvcFeatures in case it helps..
@FeatureConfiguration
public class MvcFeatures {
/**
* Enables the Spring MVC @Controller programming model.
*/
@Feature
public MvcAnnotationDriven annotationDriven(ConversionService conversionService) {
return new MvcAnnotationDriven().conversionService(conversionService)
.argumentResolvers(new CustomArgumentResolver());
}
/**
* Maps '/' requests to the 'home' view.
*/
@Feature
public MvcViewControllers viewController() {
return new MvcViewControllers("/", "index");
}
/**
* Enables Spring's component scanning feature.
*/
@Feature
public ComponentScanSpec componentScan() {
return new ComponentScanSpec("com.example.controllers").excludeFilters(
new AnnotationTypeFilter(Configuration.class), new AnnotationTypeFilter(
FeatureConfiguration.class));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
或根据文档设置分隔符:
Try
Or set the delimiters accordantly to the docs:
理查兹,试试这些。
Richards, try these.