总算把网站设计好了,广州免费孕检,非常好听的贸易公司名称大全,区块链开发与应用专业how2java今天#xff0c;我将我当前正在从事的项目之一迁移到了Spring 4.0。 由于它是我用来学习和演示Spring功能的非常简单的Web应用程序#xff0c;因此只需要更新项目的POM文件并更改Spring版本。 我将项目部署到Tomcat 7服务器#xff0c;显然该应用程序未启动。 我在I… how2java 今天我将我当前正在从事的项目之一迁移到了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批注提供了一种将名称/值属性对的源添加到Springs 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的PropertySource注释与Java 7一起在Codeleak.pl博客上使用。 翻译自: https://www.javacodegeeks.com/2013/11/how-to-using-propertysource-annotation-in-spring-4-with-java-7.htmlhow2java