autowired

Cannot get UserDetailsManager injected with Spring Boot and Java-based Configuration

二次信任 提交于 2019-12-21 12:36:12
问题 I have spring boot webapp that uses the Java-based configuration to configure a JdbcUserDetailsManager: @Configuration @EnableWebMvcSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired protected DataSource dataSource; @Autowired public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception { auth.jdbcAuthentication() .dataSource(dataSource) .usersByUsernameQuery("select username as principal, password as credentials, true from users

Spring Autowiring and Class Inheritance

旧时模样 提交于 2019-12-21 06:57:45
问题 I'm having a problem getting @Autowired to work. Sorry if I screw up any terms, I am relatively new to Spring. Spring Version is 3.0.5.RELEASE, and I am using context:component-scan in my beans definition. This works with the @Autowired annotation: @Component public class UserDao { @PersistenceContext protected EntityManager em; @Transactional public User findById(Long id) { return em.find(User.class, id); } } This does NOT work with the @Autowired annotation: @Component public class UserDao

Spring @Autowired vs using 'new' keyword to create Object [closed]

匆匆过客 提交于 2019-12-21 06:19:28
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I am learning Spring and building some experiment application. I am confused on where to use @Autowired for creating the Object. I get the part that it promotes loose coupling and also does create a new Object Every time as opposed to what 'new' keyword do. But what should we do

Is Spring's @Autowired a huge performance issue?

▼魔方 西西 提交于 2019-12-21 02:01:07
问题 I have a project that has... I dunno... 200-300 daos/services/controllers and I use @Autowired to wire everything together rather than specify everything in the applicationContext.xml . My question is, how much of a performance impact does this have on my startup times? Would it be worth it to remove all of the @Autowired annotations and actually wire this application up manually via the applicationContext.xml ? From an architectural point of view, I like @Autowired . I don't want to add

Why does Autowiring not function in a thread?

江枫思渺然 提交于 2019-12-20 23:25:17
问题 I've made a maven project in Spring 3.0, I've made some DAO, services and controllers, in one of mine controller I call a service in which I start a thread, the problem is that in the thread I declare a "service variable" that should be initialized with Autowired annotiation, but it doesn't work and the variable isn't initilized and has the value null. this is the thread class package com.project.tasks; import org.springframework.beans.factory.annotation.Autowired; import org.springframework

Spring @Autowired not working

泄露秘密 提交于 2019-12-20 19:53:11
问题 I have some problems wth autowire annotation. My app looks like this: Here is controller: @Controller public class MyController { @Autowired @Qualifier("someService") private SomeService someService; .... } It's a service layer: public interface SomeService { ... } @Service public class SomeServiceImpl implements SomeService{ @Autowired @Qualifier("myDAO") private MyDAO myDAO; .... } And DAO layer: public interface MyDAO{ .... } @Repository public class JDBCDAOImpl implements MyDAO {

Spring @Autowired not working

本小妞迷上赌 提交于 2019-12-20 19:52:01
问题 I have some problems wth autowire annotation. My app looks like this: Here is controller: @Controller public class MyController { @Autowired @Qualifier("someService") private SomeService someService; .... } It's a service layer: public interface SomeService { ... } @Service public class SomeServiceImpl implements SomeService{ @Autowired @Qualifier("myDAO") private MyDAO myDAO; .... } And DAO layer: public interface MyDAO{ .... } @Repository public class JDBCDAOImpl implements MyDAO {

How to make instance of CrudRepository interface during testing in Spring?

让人想犯罪 __ 提交于 2019-12-20 19:41:05
问题 I have a Spring application and in it I do not use xml configuration, only Java Config. Everything is OK, but when I try to test it I faced problems with enabling autowiring of components in the tests. So let's begin. I have an interface : @Repository public interface ArticleRepository extends CrudRepository<Page, Long> { Article findByLink(String name); void delete(Page page); } And a component/service: @Service public class ArticleServiceImpl implements ArticleService { @Autowired private

Spring autowiring setter/constructor PROs and CONs

不问归期 提交于 2019-12-20 12:36:51
问题 When using @Autowired (not xml configuration), could someone compare the set/constructor binding advantages and disadvantages? See the following examples: public class Example{ private Logger log; // constructor wiring @Autowired public Example(Logger log){ this.log = log; } } public class Example{ // setter wiring @Autowired private Logger log; } 回答1: It is entirely a matter of preference. Spring frowns upon constructor injection, or at least used to, because thus circular dependencies

@Autowired beans not loading after using beans:profiles in spring 3.1

那年仲夏 提交于 2019-12-20 03:52:20
问题 I have used beans:profiles in my xml like this: <beans profile="dev"> <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.internal.url}" /> <property name="username" value="${jdbc.internal.username}" /> </bean> </beans> I've set the spring.active.profiles in web.xml: <servlet> <servlet-name>myapp</servlet-name> <servlet-class>org.springframework.web