spring-4

How get working @Value or Environment in a class implementing the Condition/ConfigurationCondition interfaces

六月ゝ 毕业季﹏ 提交于 2019-12-02 11:06:36
问题 I am working with only JavaConfig. I have the following declaration: @Bean public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); } it is mandatory for JavaConfig according with the following post: Spring 3.2 @value annotation with pure java configuration does not work, but Environment.getProperty works The following code works perfect (many @Values by testing purposes): @Configuration public class

Spring 4 static content like css/js brings error 405 Request method 'GET' not supported

☆樱花仙子☆ 提交于 2019-12-02 09:01:54
I've checked around for this problem, but after 4 hours of trying many things, nothing worked for me. I get a 405 error when trying to access my css file. Here are my Config.java package com.myapp.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; import org.springframework.web.servlet.config

Spring 4.0.x JSON/Ajax HTTP/1.1 406 Not Acceptable

让人想犯罪 __ 提交于 2019-12-02 07:34:07
I am working with Spring 4.0.5.RELEASE, Spring MVC through only Java Config I have in my pom.xml the following: <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>${jackson.version}</version> </dependency> Where <jackson.version>1.9.13</jackson.version> I am using the Spring default configuration about JSON. In some @Controller I have the following: @RequestMapping(value="/getjsonperson", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE) public @ResponseBody Person getJSONPerson(){ logger.info("getJSONPerson -

How get working @Value or Environment in a class implementing the Condition/ConfigurationCondition interfaces

▼魔方 西西 提交于 2019-12-02 07:26:57
I am working with only JavaConfig. I have the following declaration: @Bean public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); } it is mandatory for JavaConfig according with the following post: Spring 3.2 @value annotation with pure java configuration does not work, but Environment.getProperty works The following code works perfect (many @Values by testing purposes): @Configuration public class ActiveMQServerConfiguration { @Value("${localhost.address}") private String localHost; @Value("${remotehost.address}"

How to target specific handlers with a @ControllerAdvice @ModelAttribute?

喜你入骨 提交于 2019-12-02 04:33:46
问题 I'd like to display a warning message on specific pages 5 minutes prior to a system shutdown. Rather than add it manually to each these pages I created a @ControllerAdvice class with a @ModelAttribute method that adds the message to the Model parameter, but from what I understand reading the documentation and SO and some initial testing this model attribute will be added to every method with a @RequestMapping. I realize I could refactor my code so that the targeted methods are all in one

How to target specific handlers with a @ControllerAdvice @ModelAttribute?

时光毁灭记忆、已成空白 提交于 2019-12-02 01:08:24
I'd like to display a warning message on specific pages 5 minutes prior to a system shutdown. Rather than add it manually to each these pages I created a @ControllerAdvice class with a @ModelAttribute method that adds the message to the Model parameter, but from what I understand reading the documentation and SO and some initial testing this model attribute will be added to every method with a @RequestMapping. I realize I could refactor my code so that the targeted methods are all in one controller and limit the @ControllerAdvice to that one controller, but I would end up with a collection of

How to configure Hikari CP for HSQL in a Spring(4) context?

爱⌒轻易说出口 提交于 2019-12-01 10:59:32
i want to use Hikari CP in my Spring 4.0.3 context but seems i am missing something. My bean configuration looks like: <bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource"> <constructor-arg> <bean class="com.zaxxer.hikari.HikariConfig"> <constructor-arg> <props> <prop key="dataSource.driverClassName">${database.driver}</prop> <prop key="dataSource.jdbcUrl">${database.database.jdbc.url}</prop> <prop key="dataSource.port">${database.port}</prop> <prop key="dataSource.databaseName">${database.name}</prop> <prop key="dataSource.user">${database.user}</prop> <prop key="dataSource

Beancreationexception+NosuchBeandefinition exception

淺唱寂寞╮ 提交于 2019-12-01 08:43:22
I am working on Spring 4 application with SpringBoot. In com.test.tm package, Application class: @SpringBootApplication @EnableJpaRepositories( repositoryFactoryBeanClass = GenericRepositoryFactoryBean.class ) @Import( { HikariDataSourceConfig.class } ) public class Application { public static void main( String[] args ) { SpringApplication.run(Application.class, args); } } In com.test.tm.entities package, User Class: @Table( name = "test.user" ) @Entity public class User implements Serializable { @Id @GeneratedValue( strategy = GenerationType.AUTO ) private Integer id; private String message;

env.getProperty not working Spring PropertyPlaceholderConfigurer

我只是一个虾纸丫 提交于 2019-12-01 06:55:12
I am loading properties file using spring <bean id="appProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations" value="classpath:/sample.properties" /> <property name="ignoreUnresolvablePlaceholders" value="true"/> </bean> when i am getting property value using @Value("${testkey}") its working fine. but when i am trying to get using env @Resource private Environment environment; environment.getProperty("testkey") // returning null A PropertyPlaceholderConfigurer does not add the properties from its locations to the Environment .

env.getProperty not working Spring PropertyPlaceholderConfigurer

纵然是瞬间 提交于 2019-12-01 04:55:30
问题 I am loading properties file using spring <bean id="appProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations" value="classpath:/sample.properties" /> <property name="ignoreUnresolvablePlaceholders" value="true"/> </bean> when i am getting property value using @Value("${testkey}") its working fine. but when i am trying to get using env @Resource private Environment environment; environment.getProperty("testkey") // returning null