高端家具东莞网站建设技术支持旅游英文网站 建设需求
高端家具东莞网站建设技术支持,旅游英文网站 建设需求,保定市工程造价信息网,中国最好的公司排名今天#xff0c;我将我当前正在从事的项目之一迁移到了Spring 4.0。 由于它是我用来学习和演示Spring功能的非常简单的Web应用程序#xff0c;因此只需要更新项目的POM文件并更改Spring版本。 我将项目部署到Tomcat 7服务器#xff0c;显然该应用程序未启动。 我在IntelliJ控… 今天我将我当前正在从事的项目之一迁移到了Spring 4.0。 由于它是我用来学习和演示Spring功能的非常简单的Web应用程序因此只需要更新项目的POM文件并更改Spring版本。 我将项目部署到Tomcat 7服务器显然该应用程序未启动。 我在IntelliJ控制台中看到此消息 Failed to load bean class: pl.codeleak.t.config.RootConfig; nested exception is org.springframework.core.NestedIOException: Unable to collect imports; nested exception is java.lang.ClassNotFoundException: java.lang.annotation.Repeatable Failed to load bean class: pl.codeleak.t.config.RootConfig; nested exception is org.springframework.core.NestedIOException: Unable to collect imports; nested exception is java.lang.ClassNotFoundException: java.lang.annotation.Repeatable Failed to load bean class: pl.codeleak.t.config.RootConfig; nested exception is org.springframework.core.NestedIOException: Unable to collect imports; nested exception is java.lang.ClassNotFoundException: java.lang.annotation.Repeatable 。 什么…… java.lang.annotation.Repeatable注释是用于标记注释以供Java 8中多次使用的元注释但我在项目中使用Java 7。 例如 Repeatable(Schedules.class)
public interface Schedule { ... }Schedule(dayOfMonthlast)
Schedule(dayOfWeekFri, hour23)
public void doPeriodicCleanup() { ... } 此处对此进行了很好的描述 http : //docs.oracle.com/javase/tutorial/java/annotations/repeating.html 。 Spring 4在其PropertySource批注中利用了此功能。 提醒您 PropertySource批注提供了一种将名称/值属性对的源添加到Spring的Environment的机制 它与Configuration类结合使用。 您可能已经知道我正在自己的配置中使用此功能 Configuration
PropertySource(classpath:/datasource.properties)
public class DefaultDataSourceConfig implements DataSourceConfig {Autowiredprivate Environment env;OverrideBeanpublic DataSource dataSource() {DriverManagerDataSource dataSource new DriverManagerDataSource();dataSource.setDriverClassName(env.getRequiredProperty(dataSource.driverClassName));dataSource.setUrl(env.getRequiredProperty(dataSource.url));dataSource.setUsername(env.getRequiredProperty(dataSource.username));dataSource.setPassword(env.getRequiredProperty(dataSource.password));return dataSource;}
} 我首先想到的是Spring不再与低于8的Java兼容。 不可能。 虽然这样做GitHub上查找我发现了一个全新的PropertySources注释是一个容器PropertySource注解。 那就是我针对Java兼容性问题的解决方案在我的配置类上使用PropertySources注释如下所示 Configuration
PropertySources(value {PropertySource(classpath:/datasource.properties)})
public class DefaultDataSourceConfig implements DataSourceConfig {Autowiredprivate Environment env;} 就是这样 进行此更改后我的应用程序开始运行我可以看到它运行正常 编辑 请参阅 https //jira.springsource.org/browse/SPR-11086 参考操作方法在Springle 4中通过我们的JCG合作伙伴 Rafal Borowiec在Javale 7中使用PropertySource批注在 Codeleak.pl博客上。 翻译自: https://www.javacodegeeks.com/2013/11/how-to-using-propertysource-annotation-in-spring-4-with-java-7.html
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/88117.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!