autowired

Spring 3.0.5 doesn't evaluate @Value annotation from properties

拥有回忆 提交于 2019-12-17 15:47:16
问题 Trying to auto-wire properties to a bean in Spring 3.0.5.RELEASE , I'm using: config.properties : username=myusername main-components.xml : <context:property-placeholder location="classpath:config.properties" /> MyClass: @Service public class MyClass { @Value("${username}") private String username; ... } As a result, username gets set to literally "${username}" , so the expression doesn't get parsed. My other auto-wired dependencies on this class get set, and Spring doesn't throw any

Spring injects dependencies in constructor without @Autowired annotation

女生的网名这么多〃 提交于 2019-12-17 15:39:18
问题 I'm experimenting with examples from this official Spring tutorials and there is a dependency on this code: https://github.com/spring-guides/gs-async-method/tree/master/complete If you look at the code on AppRunner.java class, I have 2 questions: When server is starting, if I put a breakpoint in this class's constructor, seems like in the constructor, the GitHubLookupService is provided by spring, using the @Service bean that was configured. BUT, there was no @Autowired annotation on the

Spring Boot - Environment @Autowired throws NullPointerException

耗尽温柔 提交于 2019-12-17 09:41:35
问题 I have a project setup using Spring Boot 0.5.0.M5 . In one of the configuration files I am trying to @Autowire Environment but that fails with a NullPointerException . Here's what I have so far: Application.java @EnableAutoConfiguration @Configuration @ComponentScan public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } JpaConfig.java where I am trying to @Autowire Environment @Configuration @EnableTransactionManagement

Spring Boot - Environment @Autowired throws NullPointerException

人盡茶涼 提交于 2019-12-17 09:41:20
问题 I have a project setup using Spring Boot 0.5.0.M5 . In one of the configuration files I am trying to @Autowire Environment but that fails with a NullPointerException . Here's what I have so far: Application.java @EnableAutoConfiguration @Configuration @ComponentScan public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } JpaConfig.java where I am trying to @Autowire Environment @Configuration @EnableTransactionManagement

Spring can you autowire inside an abstract class?

谁说胖子不能爱 提交于 2019-12-17 09:14:37
问题 Spring is failing to autowire my object? Is it possible to autowire an object within an abstract class. Assume all schemas are supplied in application-context.xml Question: What annotation should be on the base and extending classes (if any) @Service @Component? Example abstract class SuperMan { @Autowire private DatabaseService databaseService; abstract void Fly(); protected void doSuperPowerAction(Thing thing) { //busy code databaseService.save(thing); } } Extending class public class

Using Spring 3 autowire in a standalone Java application

强颜欢笑 提交于 2019-12-17 03:48:26
问题 Here is my code: public class Main { public static void main(String[] args) { Main p = new Main(); p.start(args); } @Autowired private MyBean myBean; private void start(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/config.xml"); System.out.println("my beans method: " + myBean.getStr()); } } @Service public class MyBean { public String getStr() { return "string"; } } <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3

How to autowire on transaction class?

試著忘記壹切 提交于 2019-12-14 04:03:30
问题 Class file: @Transactional(propagation=Propagation.REQUIRES_NEW) public class ServiceImpl implements Service { ... } Xml file: ... <bean id="service" class="com.sky.core.engine.impl.ServiceImpl"> ... Test File: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("testConfig.xml") public class ServiceImplTest { private static final Logger log = Logger .getLogger(ServiceImplTest.class); @Autowired private ServiceImpl service; @Test public void test(){ ... } Exception: org

Spring autowire with dynamic Constructor Parameters using annotation approach

时光毁灭记忆、已成空白 提交于 2019-12-14 02:39:19
问题 @Component public class Module { public Module(String type, List<String> data) { . . . } } How do I initialize User, while passing the constructor's parameters, where Module is Autowired into another class: where the parameter values here are dynamic, whereby, for example, they are fetched via a user submission form, thereby can't be stored in a file. @Component public class AnotherClass { @Autowired Module module(....)????? // How do I do it here . . . } In this case, type parameter in

@Autowired for @ModelAttribute

寵の児 提交于 2019-12-13 16:54:15
问题 I'm very new to Spring and I'm encountering the following problem. I've got the following Controller, in which the @Autowired works perfectly (tried debugging and it works fine). @Controller @RequestMapping(value = "/registration") @SessionAttributes("rf") public class RegistrationController { @Autowired UserJpaDao userDao; @RequestMapping(method = RequestMethod.GET) @Transactional public String setupForm(Model model) throws Exception { model.addAttribute("rf", new RegistrationForm()); return

Spring Data Neo4j - @Autowired Repository == null

試著忘記壹切 提交于 2019-12-13 15:24:01
问题 I try to write a webapp using Spring Data Neo4j. I have an Repository: public interface UserRepository extends GraphRepository<Neo4jUser> {} an applicationcontext.xml: ... <context:component-scan base-package="de.wilke.test.neo4j" > <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!-- REST Connection to Neo4j server --> <bean id="restGraphDatabase" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">